|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-03-12 01:56 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 14:00:01 2025 UTC |
When making two simultaneous connections to a MySQL server using the same username / password combination, the MySQL link resource returned is the same. The upshot of this is that I am unable to use these 2 connections to simultaneously work with 2 different databases that happen to share one user/pass set. Put simply: If I call mysql_select_db() on one connection, it changes the selected DB on the other connection, too. The following code illustrates the sharing of the connection by executing a bogus query on one connection then calling mysql_error() on both connections. <? $conn1 = mysql_connect ("localhost", "sales", "xxxx"); $conn2 = mysql_connect ("localhost", "sales", "xxxx"); mysql_select_db("sales", $conn1); mysql_select_db("salesNEW", $conn2); mysql_query("SELECT blah FROM blah", $conn1); echo mysql_error($conn1)."<br />"; echo mysql_error($conn2); echo "<br /><br />"; echo $conn1."<br />"; echo $conn2; ?> The output is: Table 'salesNEW.blah' doesn't exist Table 'salesNEW.blah' doesn't exist Resource id #2 Resource id #2 Notice that I'm executing the broken query on $conn1. Yet the error message is returned on both $conn1 and $conn2. Also notice that the Resource id's are both 2, which easily explains this behavior. It gets more bizarre when I swap over to mysql_pconnect(). The output becomes: Table 'salesNEW.blah' doesn't exist Table 'salesNEW.blah' doesn't exist Resource id #2 Resource id #3 So the behaviour is the same, but PHP clearly thinks it has 2 seperate connections this time. To determine whether PHP or MySQL was causing this bug, I used 2 simultaneous instances of the mysql command line client and verified that it happily coped with the situation.