|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42392 Multiple Connections to the same Server and Login Override Previous Connections
Submitted: 2007-08-23 00:45 UTC Modified: 2007-08-23 09:10 UTC
From: memso at memso dot net Assigned:
Status: Not a bug Package: MSSQL related
PHP Version: 5.2.3 OS: Windows 2003 Server
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.
Block user comment
Status: Assign to:
Bug Type:
From: memso at memso dot net
New email:
PHP Version: OS:


 [2007-08-23 00:45 UTC] memso at memso dot net
After creating a MSSQL connection, any subsequent connections to MSSQL, whether persistant or otherwise, using the same server and login information, will override the original MSSQL connection. Using two different logins do not cause the problem.

This has been tested and found to occur in PHP 5.2.0 and 5.2.3 for Windows (Windows 2003 Server) as well as PHP 5.2.3 for Linux (a heavily customized v2.2.24).

This is very similar to Bug #17305.

Reproduce code:
$testquery = "SELECT EMAILADDRESS FROM adminmain WHERE ID = 1";

$conn1 = mssql_connect("localhost", "sa", "********");
mssql_select_db("generic", $conn1);

// First Query!
$result = mssql_query($testquery, $conn1);
$qarray = mssql_fetch_array($result);
echo("First Result: " . $qarray["EMAILADDRESS"] . "<br />");

$conn2 = mssql_connect("localhost", "sa", "********");
mssql_select_db("buymanitou", $conn2);

// Second Query!
$result = mssql_query($testquery, $conn1);
$qarray = mssql_fetch_array($result);
echo("Second Result: " . $qarray["EMAILADDRESS"] . "<br />");


Expected result:
In my test case, I am grabbing an email address from the first administrator in the system from the first database connection. Since in my case, the first DB connection returns , I expect the following output:

First Result:
Second Result:

Actual result:
Because of the bug, the email address from the SECOND database is returned for the second query:

First Result:
Second Result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-23 09:10 UTC]

"If a second call is made to mssql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. "

To create separate link you need to use the 4th optional boolean parameter (set to true).

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Dec 06 15:01:27 2023 UTC