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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 20:01:31 2024 UTC