As has been already commented, opening multiple connection handles with:
<?php
$connection_handle = mysql_connect($hostname_and_port,$user,$password);
?>
causes the connection ID/handle to be REUSED if the exact same parameters are passed in to it. This can be annoying if you want to work with multiple databases on the same server, but don't want to (a) use the database.table syntax in all your queries or (b) call the mysql_select_db($database) before every SQL query just to be sure which database you are working with.
My solution is to create a handle for each database with mysql_connect (using ever so slightly different connection properties), and assign each of them to their own database permanently. each time I do a mysql_query(...) call, I just include the connection handle that I want to do this call on eg (ive left out all error checking for simplicity sake):
<?php
$handle_db1 = mysql_connect("localhost","myuser","apasswd");
$handle_db2 = mysql_connect("127.0.0.1","myuser","apasswd");
$handle_db3 = mysql_connect("localhost:3306","myuser","apasswd");
$handle_db4 = mysql_connect("localhost","otheruser","apasswd");
mysql_select_db("db1",$handle_db1);
mysql_select_db("db2",$handle_db2);
mysql_select_db("db3",$handle_db3);
mysql_select_db("db4",$handle_db4);
$query = "select * from test"; $which = $handle_db1;
mysql_query($query,$which);
$query = "select * from test"; $which = $handle_db2;
mysql_query($query,$which);
?>
Note that we didn't do a mysql_select_db between queries , and we didn't use the database name in the query either.
Of course, it has the overhead of setting up an extra connection.... but you may find this is preferable in some cases...