#17593 [Com]: mssql_query doesn't fetch results properly

From: Date: Fri, 31 Oct 2003 13:41:12 +0000
Subject: #17593 [Com]: mssql_query doesn't fetch results properly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-49762@lists.php.net to get a copy of this message
ID: 17593 Comment by: adimuraru at rdslink dot ro Reported By: alexp at mail dot lv Status: Closed Bug Type: MSSQL related Operating System: Win2k prof. SP2 PHP Version: 4.2.1 New Comment: This error occurs when you try to send a new command to the server before all the results of the previous command on the same connection have been completely processed. A connection in mssql library used in php is single-threaded and synchronous; it can handle only one request to the server at a time. So, if you want to pass multiple query to a database make a single batch query(with multiple queries): $RS=mssql_query(select * from table1 select * from tabel2); and use mysql_next_result to fetch all records. After use result set make sure you deallocate resources with mssql_free_result($rs) before make another request to sql server in the same script Previous Comments: ------------------------------------------------------------------------ [2002-12-03 12:07:05] fmk@php.net In PHP 4.3.0 you will be able to fix this problem by calling mssql_free_result($r1); after the first statement. When you use if statements MSSQL server seams to hold the result (blocing for other statements) until the result is released. ------------------------------------------------------------------------ [2002-06-04 06:38:50] alexp at mail dot lv It seems that mssql_query fails to get results properly after executing some arbitrary queries. <?php mssql_connect(".","login","passwd"); $r1=mssql_query("if object_id('tempdb..#abc') is not null drop table #abc"); $r2=mssql_query("select * from sometable"); $r3=mssql_query("select * from othertable"); ?> ..causes.. Warning: MS SQL error: Attempt to initiate a new SQL Server operation with results pending. (severity 7) in d:\htdocs\t\bug.php on line 4 Warning: MS SQL: Query failed in d:\htdocs\t\bug.php on line 4 Warning: MS SQL error: Attempt to initiate a new SQL Server operation with results pending. (severity 7) in d:\htdocs\t\bug.php on line 5 Warning: MS SQL: Query failed in d:\htdocs\t\bug.php on line 5 ---- First query is correct and executes properly (checked with SQL server profiler running). But 2nd,3rd..n-th fail to execute. Though if I comment out 1st one, others work ok. Another dirty hack to avoid these errors is to embed entire query in exec(""). But then temporary #tables won't be available in next queries. I've found another similar bug in database, #9379. Using sql variables in query causes same weird behaviour... In a few days I will test this script on Linux/apache/php/freedts connecting to same sql database and see if it works. Any ideas? ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17593&edit=1

« previous php.bugs (#49762) next »