ID: 26465 User updated by: _nospam_svbev at umail dot ru Reported By: _nospam_svbev at umail dot ru -Status: Bogus +Status: Open Bug Type: MSSQL related Operating System: Win2k PHP Version: 4CVS-2003-11-28 (stable) New Comment:
The first example is the correct way too and does the same but has the different result. And THIS IS A BUG. ============================================================ example #1 (Reproduce code) $conn2 is a local var. of step2 ============================================================ 1: $conn1 = mssql_connect( $servername, $user, $pswd ); 2: mssql_select_db ( $dbname, $conn1 ); 3: step2( $servername, $dbname, $user, $pswd, $strquery ); 4: step2( $servername, $dbname, $user, $pswd, $strquery ); !!! $conn1 IS NOT A VALID connection link now ============================================================ When I delete 'step2()' calls and insert the body of 'step2()' function then connection link in $conn1 remains VALID till the end. ============================================================ example #2 (Working code) $conn2 is a global variable ============================================================ 1: $conn1 = mssql_connect( $servername, $user, $pswd ); 2: mssql_select_db ( $dbname, $conn1 ); 3: $conn2 = mssql_connect( $servername, $user, $pswd ); mssql_select_db ( $dbname, $conn2 ); mssql_close( $conn2 ); 4: $conn2 = mssql_connect( $servername, $user, $pswd ); mssql_select_db ( $dbname, $conn2 ); mssql_close( $conn2 ); !!! $conn1 IS A VALID connection link now ============================================================ Do you see the difference? The state of the first connection depends on the variable scope containing $conn2 variable. This difference is a bug. function step2( $servername, $dbname, $user, $pswd, $strquery ) { $conn2 = mssql_connect( $servername, $user, $pswd ); mssql_select_db ( $dbname, $conn2 ); mssql_close( $conn2 ); } Thank you. Previous Comments: ------------------------------------------------------------------------ [2003-12-01 02:08:23] [EMAIL PROTECTED] The last example is the correct way. ------------------------------------------------------------------------ [2003-12-01 01:44:08] _nospam_svbev at umail dot ru Sorry, the error in the comments inside WORKING CODE: // $conn1 is a valid resource now. comment should be in all cases. ------------------------------------------------------------------------ [2003-12-01 01:36:10] _nospam_svbev at umail dot ru Dear snipper, I read the docs and know that the same link is used for the second connection. Why is not this link closed after <open>,<open>,<close> secquence? A query is executed successfully after this. So I suppose that PHP counts how many times this link is opened and PHP closes this link after this counter is zeros. (Otherwise the bug is that the WORKING CODE below works.) The problem is that PHP counts LINK opening differently depending on the code structure. The same sequence of mssql_ calls, when coded differently, gives different results. The code below performs all the same steps as the REPRODUCE CODE does but WORKS SUCCESSFULLY. It outputs the rowset as expected. The WORKING CODE does not contain step2() function. So $conn1 and $conn2 variables which keeps connection handles are located in one variable scope. WORKING CODE (THE ONLY VARIABLE SCOPE): --------------- // 1. $conn1 = mssql_connect( $servername, $user, $pswd ); mssql_select_db ( $dbname, $conn1 ); // $conn1 is a valid resource here. // 2. $conn2 = mssql_connect( $servername, $user, $pswd ); mssql_select_db ( $dbname, $conn2 ); mssql_close( $conn2 ); // $conn1 is still a valid resource. // 3. $conn2 = mssql_connect( $servername, $user, $pswd ); mssql_select_db ( $dbname, $conn2 ); mssql_close( $conn2 ); // $conn1 is not a valid resource now. // 4. $result = mssql_query( $strquery, $conn1 ); if( !$result ) echo "Step 4 FAILED: $php_errormsg <br>"; Thank you. Alla. ------------------------------------------------------------------------ [2003-11-30 04:15:19] [EMAIL PROTECTED] 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-11-29 15:06:47] _nospam_svbev at umail dot ru where $php_errormsg is: 'mssql_query(): <RSRC_ID> is not a valid MS SQL-Link resource' ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/26465 -- Edit this bug report at http://bugs.php.net/?id=26465&edit=1