From:             _nospam_svbev at umail dot ru
Operating system: Win2k
PHP version:      4CVS-2003-11-28 (stable)
PHP Bug Type:     MSSQL related
Bug description:  mssql_close() closes more than one connection.

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;

-- 
Edit bug report at http://bugs.php.net/?id=26465&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=26465&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=26465&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=26465&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=26465&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=26465&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=26465&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=26465&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=26465&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=26465&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=26465&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=26465&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=26465&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26465&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=26465&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=26465&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=26465&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=26465&r=float

Reply via email to