How does PHP know what the last database connection is when mysql_select_db() or mysql_query() is used without the optional database parameter?
<p>Consider the following code:</p>

<pre><code>&lt;?php

$conn = mysql_connect('localhost', 'username', 'password');
mysql_select_db('database', $conn);

?&gt;
</code></pre>

<p>This works as expected, but how does PHP know what database connection to use when calling <code>mysql_select_db()</code> in the following example?</p>

<pre><code>&lt;?php

mysql_connect('localhost', 'username', 'password');
mysql_select_db('database');

?&gt;
</code></pre>

<p>The PHP documentation states that "If the link identifier is not specified, the last link opened by mysql_connect() is assumed." (<a href="http://us3.php.net/manual/en/function.mysql-select-db.php" rel="nofollow">PHP: mysql_select_db()</a>)</p>

<p>Where is the last connection stored or retrieved from?</p>
