php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17593 mssql_query doesn't fetch results properly
Submitted: 2002-06-04 06:38 UTC Modified: 2002-12-03 12:07 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: alexp at mail dot lv Assigned:
Status: Closed Package: MSSQL related
PHP Version: 4.2.1 OS: Win2k prof. SP2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
44 + 7 = ?
Subscribe to this entry?

 
 [2002-06-04 06:38 UTC] 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?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-03 12:07 UTC] 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.
 [2003-10-31 08:41 UTC] adimuraru at rdslink dot ro
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 03:01:27 2024 UTC