|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2007-10-11 02:41 UTC] memso at memso dot net
 Description:
------------
After creating a persistent MSSQL connection, any subsequent persistent connections to MSSQL, using the same server and login information with the fourth parameter (new_link) set to TRUE, will cause problems when using the first link again.
This has been tested and found to occur in PHP 5.2.3 and 5.2.4 for
Windows (Windows 2003 Server) on three very different servers. A completely different problem occurs in PHP 5.2.3 for Linux. Since PHP 5.2.4 didn't fix the problem in Windows, I haven't tried it yet in Linux.
**NOTE: Using mssql_connect does NOT cause this problem. Also, if the login information is different for the two connections, this test example works properly. It seems to only occur from using mssql_pconnect with the same login information and $new_link set to TRUE.
Reproduce code:
---------------
<?php
	$testquery = "SELECT EMAILADDRESS FROM adminmain WHERE ID = 1";
	
	$conn1 = mssql_pconnect("localhost", "sa", "******", TRUE);
	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_pconnect("localhost", "sa", "******", TRUE);
	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 (note that changing the two mssql_pconnect to mssql_connect, it works as expected):
First Result: fakeemailaddress@something.net
Second Result: fakeemailaddress@something.net
Actual result:
--------------
On the Windows Server, this is the output:
First Result: fakeemailaddress@something.net
Warning: mssql_query() [function.mssql-query]: Unable to set query in C:\...\test-mssql_pconnect.php on line 17
Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-result resource in C:\...\test-mssql_pconnect.php on line 18
Second Result: 
On the Linux server, PHP seems to crash or puke out. I do not get a log entry in my phperrors.log nor in my apache2/logs/domainname-error_log. However, as long as I use exit; before the second mssql_query call, I get output. If I move it to just afterwards, nothing shows up, so I'm assuming it's using mssql_query after creating the second connection that is having issues.
Since these both may be due to the same issue, I am tracking it under a single report.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 10:00:02 2025 UTC | 
After looking into code provided. Solution : your trying to connect to other database without close connection to first data. if you would like work with multiple databases. you should release free ( close ) first connection try to connect next one. Line mssql_close($conn1); should be before $conn2 = mssql_pconnect("localhost", "sa", "******", TRUE); not at the end of code. Modified code. <?php $testquery = "SELECT EMAILADDRESS FROM adminmain WHERE ID = 1"; $conn1 = mssql_pconnect("localhost", "sa", "******", TRUE); mssql_select_db("generic", $conn1); // First Query! $result = mssql_query($testquery, $conn1); $qarray = mssql_fetch_array($result); echo("First Result: " . $qarray["EMAILADDRESS"] . "<br />"); mssql_close($conn1); $conn2 = mssql_pconnect("localhost", "sa", "******", TRUE); 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($conn2); ?>