php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22654 Simultaneous connections with same user/password do not work.
Submitted: 2003-03-12 01:00 UTC Modified: 2003-03-12 01:56 UTC
From: JULES at SITEPOINT dot COM Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.3.0 OS: RH linux 2.4.18
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: JULES at SITEPOINT dot COM
New email:
PHP Version: OS:

 

 [2003-03-12 01:00 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-12 01:56 UTC] sniper@php.net
http://www.php.net/manual/fi/function.mysql-connect.php

Note the 4th parameter..

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 22:01:34 2025 UTC