note 82040 added to function.mysql-connect
| From: | arithmetric at gmail dot com | Date: | Tue, 25 Mar 2008 18:59:58 +0000 |
| Subject: | note 82040 added to function.mysql-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137570@lists.php.net to get a copy of this message | ||
If you are trying to open multiple, separate MySQL connections with the same MySQL user, password,
and hostname, you must set $new_link = TRUE to prevent mysql_connect from using an existing
connection.
For example, you are opening two separate connections to two different databases (but on the same
host, and with the same user and password):
$db1 = mysql_connect($dbhost, $dbuser, $dbpass);
$rv = mysql_select_db($dbname1, $db1);
$db2 = mysql_connect($dbhost, $dbuser, $dbpass);
$rv = mysql_select_db($dbname2, $db2);
At this point, both $db1 and $db2 will have selected the database named by $dbname2.
The workaround is to require that the second MySQL connection is new:
$db1 = mysql_connect($dbhost, $dbuser, $dbpass);
$rv = mysql_select_db($dbname1, $db1);
$db2 = mysql_connect($dbhost, $dbuser, $dbpass, TRUE);
$rv = mysql_select_db($dbname2, $db2);
Now, $db1 should have selected $dbname1, and $db2 should have selected $dbname2.
This has been documented on the mysql_select_db page as well.
Note: This occurs only when the server, username, and password parameters are identical for each
mysql_connect statement.
----
Server IP: 64.71.164.2
Probable Submitter: 75.168.221.90
----
Manual Page -- http://www.php.net/manual/en/function.mysql-connect.php
Edit -- https://master.php.net/note/edit/82040
Del: integrated -- https://master.php.net/note/delete/82040/integrated
Del: useless -- https://master.php.net/note/delete/82040/useless
Del: bad code -- https://master.php.net/note/delete/82040/bad+code
Del: spam -- https://master.php.net/note/delete/82040/spam
Del: non-english -- https://master.php.net/note/delete/82040/non-english
Del: in docs -- https://master.php.net/note/delete/82040/in+docs
Del: other reasons-- https://master.php.net/note/delete/82040
Reject -- https://master.php.net/note/reject/82040
Search -- https://master.php.net/manage/user-notes.php