php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38924 mssql_next_result returns FALSE on multiple Resultsets
Submitted: 2006-09-22 11:16 UTC Modified: 2006-09-22 17:08 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: info at benjamin-wilger dot de Assigned:
Status: Not a bug Package: MSSQL related
PHP Version: 4.4.4 OS: Windows
Private report: No CVE-ID: None
 [2006-09-22 11:16 UTC] info at benjamin-wilger dot de
Description:
------------
mssql_next_result returns FALSE on multiple Resultsets if a simple select has been executed and the data is fetched before. If one doesn't run a query before running a multiple query batch (e.g. Stored Procedure) it works fine. Look at the reproduce code to completly understand the problem.

Tested on PHP 4.3.11 (*not* buggy), 4.4.1 (*not* buggy), 4.4.2 (buggy), 4.4.3 (buggy), 4.4.4 (buggy), 5.1.4 (buggy).

Reproduce code:
---------------
<?php
mssql_connect(...); mssql_select_db(...);
$result = mssql_query('SELECT 1');
while($row = mssql_fetch_array($result)) {
  $rows_first_query[] = $row;
}

$result = mssql_query('SELECT 1 SELECT 2 SELECT 3'); // Would return three rows
do {
  while($row = mssql_fetch_array($result)) {
    $rows_first_query[] = $row;
  }
} while ($next_result = mssql_next_result($result)); // Will return FALSE in any version after 4.4.1 in this case


Expected result:
----------------
On systems with PHP 4.4.1 or lower it will run fine $rows_first_query has one row
$rows_second_query has *three* rows

Actual result:
--------------
Any version above (including 5.1.x branch) will return just one row in $rows_second_query.

WORKAROUND to get it running: Run mssql_free_result() after the every fetching of data.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-22 17:08 UTC] fmk@php.net
You should always release the result when you are done with it or use a new variable name for each result if you want to keep multiple results open.

Two ways to make your code work:

<?php
$con = mssql_connect("localhost", "sa", "s2sihaviv");
$result = mssql_query('SELECT 1', $con);
while($row = mssql_fetch_array($result)) {
	$rows_first_query[] = $row;
}
$result2 = mssql_query('SELECT 13; SELECT 2; SELECT 3', $con); // Would return three rows
do {
	while($row = mssql_fetch_array($result2)) {
		$rows_first_query[] = $row;
	}
} while ($next_result = mssql_next_result($result2)); // Will return FALSE

print_r($rows_first_query);
?>


<?php
$con = mssql_connect("localhost", "sa", "s2sihaviv");
$result = mssql_query('SELECT 1', $con);
while($row = mssql_fetch_array($result)) {
	$rows_first_query[] = $row;
}
mssql_free_result($result);
$result = mssql_query('SELECT 13; SELECT 2; SELECT 3', $con); // Would return three rows
do {
	while($row = mssql_fetch_array($result)) {
		$rows_first_query[] = $row;
	}
} while ($next_result = mssql_next_result($result)); // Will return FALSE

print_r($rows_first_query);
?>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC