#42923 [Opn]: mssql_pconnect with the same login and new_link set to true causes problems

From: Date: Thu, 11 Oct 2007 03:23:14 +0000
Subject: #42923 [Opn]: mssql_pconnect with the same login and new_link set to true causes problems
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-118379@lists.php.net to get a copy of this message
ID: 42923 User updated by: memso at memso dot net Reported By: memso at memso dot net Status: Open Bug Type: MSSQL related Operating System: Windows 2003 Server PHP Version: 5.2.4 New Comment: In the sample code provided above, I did not output the mssql_get_last_message if the second query failed. After changing it so that it does, I get this error: Changed database context to 'buymanitou'. By looking at previous bug reports, this would seem to mean that the first link to MSSQL had taken on the new database context of the second link, as if it wasn't properly creating a new link. Previous Comments: ------------------------------------------------------------------------ [2007-10-11 02:41:02] 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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42923&edit=1

« previous php.bugs (#118379) next »