php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41244 Multiple Queries in MSSQL Kills Connection and Prevents New Connections
Submitted: 2007-04-30 17:58 UTC Modified: 2007-04-30 20:22 UTC
From: mallinger at tc dot edu Assigned:
Status: Not a bug Package: MSSQL related
PHP Version: 5.2.1 OS: Windows 2003 Server
Private report: No CVE-ID: None
 [2007-04-30 17:58 UTC] mallinger at tc dot edu
Description:
------------
When executing multiple queries from a single mssql_query call, the connection is lost and subsequent connections cannot be created.  There are similar problems documented for PHP4, but it seems that (a) this is not documented for PHP5; and (b) the inability to create subsequent connections is not documented.  In particular, it seems the mssql_select_db is what is failing in the second connection.

Reproduce code:
---------------
$conn = mssql_connect('host', 'user', 'pass');
mssql_select_db("db", $conn);
mssql_query("QUERY 1", $conn);
mssql_query("QUERY 2; QUERY 3; QUERY 4;", $conn);
// this will fail:
mssql_query("QUERY 5", $conn);
// this is ok
mssql_close($conn);
// everything below will fail too:
$conn2 = mssql_connect('host', 'user', 'pass');
mssql_select_db("db", $conn2);
mssql_query("QUERY 6", $conn2);

Expected result:
----------------
The queries should execute with no problems.

Actual result:
--------------
Everything after the multiple query mssql_query call ("QUERY 2; QUERY 3; QUERY 4;" will fail.  New connections fail when trying to select a database ("mssql_select_db() [function.mssql-select-db]: Unable to select database:...") and the existing connection cannot be used anymore ("mssql_query() [function.mssql-query]: Query failed in...") .



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-30 20:22 UTC] fmk@php.net
MS SQL server does not allow new queries on the same connection as long as there are results pending the clients actions. Either fetch all data or release the result before sending new queries.

Another solution is to have multiple connections. mssql_connect() supports an optional parameter to force the creation of a new connection even if host, user and password is the same as for an existing connection.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Sep 29 01:04:48 2022 UTC