php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: memso at memso dot net
New email:
PHP Version: OS:

 

 [2007-08-23 00:45 UTC] memso at memso dot net
Description:
------------
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!
// NOTE THAT THIS IS ON CONN1 AGAIN!
$result = mssql_query($testquery, $conn1);
$qarray = mssql_fetch_array($result);
echo("Second Result: " . $qarray["EMAILADDRESS"] . "<br />");

mssql_close($conn1);
mssql_close($conn2);


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 fakeemailaddress@something.net , I expect the following output:

First Result: fakeemailaddress@something.net
Second Result: fakeemailaddress@something.net


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

First Result: fakeemailaddress@something.net
Second Result: anotheraddress@somethingelse.com

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-23 09:10 UTC] jani@php.net
RTFM: http://php.net/mssql_connect

"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-2022 The PHP Group
All rights reserved.
Last updated: Sat Sep 24 23:05:52 2022 UTC