|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-01-01 23:11 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 04:00:02 2025 UTC |
Description: ------------ The code for reproducing is self-explanatory. Anyway, the problem appears when handling multiple connections to the same database with the same login and passwords. I'm testing a script that handles connections to multiple MySQL databases, and for testing purposes I need to operate with two separated local database. However, the connection is only distinguished by the database name, while you use only host, user, and password for hashing the single connection. This results in a collision when opening the second connection, and makes it impossible to recover the previous one using mysql_connect()'s existing link functionality, even if the connection itself is still open. Reproduce code: --------------- <?php /* create primary connection */ $r1 = mysql_connect("localhost", "root", "*****", TRUE); mysql_select_db("dbname1", $r1) or die(mysql_error()); var_dump($r1); /* create auxiliary connection */ $r2 = mysql_connect("localhost", "root", "*****", TRUE); mysql_select_db("dbname2", $r2) or die(mysql_error()); var_dump($r2); /* get rid of auxiliary connection when done */ mysql_close($r2); /* fetch back the previous connection as default! */ $r3 = mysql_connect("localhost", "root", "******"); var_dump($r3); exit(); Expected result: ---------------- resource(4) of type (mysql link) resource(5) of type (mysql link) resource(4) of type (mysql link) Actual result: -------------- resource(4) of type (mysql link) resource(5) of type (mysql link) resource(6) of type (mysql link)