ID:               22654
 Updated by:       [EMAIL PROTECTED]
 Reported By:      JULES at SITEPOINT dot COM
-Status:           Open
+Status:           Bogus
 Bug Type:         MySQL related
 Operating System: RH linux 2.4.18
 PHP Version:      4.3.0
 New Comment:

http://www.php.net/manual/fi/function.mysql-connect.php

Note the 4th parameter..



Previous Comments:
------------------------------------------------------------------------

[2003-03-12 01:00:28] JULES at SITEPOINT dot COM

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.

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=22654&edit=1

Reply via email to