php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26465 mssql_close() closes more than one connection.
Submitted: 2003-11-29 11:46 UTC Modified: 2003-12-01 05:57 UTC
From: _nospam_svbev at umail dot ru Assigned:
Status: Not a bug Package: MSSQL related
PHP Version: 4CVS-2003-11-28 (stable) OS: Win2k
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: _nospam_svbev at umail dot ru
New email:
PHP Version: OS:

 

 [2003-11-29 11:46 UTC] _nospam_svbev at umail dot ru
Description:
------------
mssql_close() closes more than one open connection for the same account depending on variable scopes containing $connection_id variable.

The last STEP in the following sequence with the CONDITIONS FAILED
STEPS:
1.  establish connection #1
2.  establish connection #2 and close it
2a. repeat 2 (connect and close this connection)
3.  execute a query under connection #1      -  FAILED

CONDITIONS:
1.  all the connections use the same username and password,
2.  step #2 is performed inside a function

Step 3 failed with '<RESOURCE_ID> is not a valid MS SQL-Link resource' message. It looks like the conn.#1 is closed.

Some modifications of this algorithm WORK without any error.
All above WORKS if do not repeat connection #2 (remove step 2a).
Also all above (1,2,2a,3) WORKS if connection #2 is established for a different user.

The code below contains 'step2()' function which just opens and closes the db connection. So the variables which handle resources for connections #1 & #2 belong to separate variable scopes. 

If I remove this function and insert its code instead of its call (the common variable scope is used) then ALL WORKS!

Reproduce code:
---------------
//
// initialize variables
//
$servername = 'servername';
$dbname     = 'dbname';
$user       = 'login';
$pswd       = 'pswd';
$strquery   = 'select * from tablename';

// 1.
$conn1 = mssql_connect( $servername, $user, $pswd );
mssql_select_db ( $dbname, $conn1 );

// 2.
step2( $servername, $dbname, $user, $pswd, $strquery );
// $conn1 is still a valid resource.

// 2a.
step2( $servername, $dbname, $user, $pswd, $strquery );

// 3.
$result = mssql_query( $strquery, $conn1 );
if( !$result )
    echo "Step 3 FAILED: $php_errormsg <br>";
else
    // print the recordset


// connect/disconnect
function step2( $servername, $dbname, $user, $pswd, $strquery )
{
    $conn2 = mssql_connect( $servername, $user, $pswd );
    mssql_select_db ( $dbname, $conn2 );
    mssql_close( $conn2 );
}

Expected result:
----------------
The query is processed successfully and the recordset is printed.

Actual result:
--------------
"Step 3 FAILED: $php_errormsg" is printed;

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-29 15:06 UTC] _nospam_svbev at umail dot ru
where $php_errormsg is: 
'mssql_query(): <RSRC_ID> is not a valid MS SQL-Link resource'
 [2003-11-30 04:15 UTC] sniper@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

RTFM:
"In case 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."
 [2003-12-01 05:57 UTC] sniper@php.net
About your initial example:

When you close the connection, be it inside function or not,
of course you can't use it anymore.
The connection is reused when you use same credentials.

This is NOT bug but expected behaviour.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 19:01:29 2024 UTC