ID: 38924
Updated by: [EMAIL PROTECTED]
Reported By: info at benjamin-wilger dot de
-Status: Open
+Status: Bogus
Bug Type: MSSQL related
Operating System: Windows
PHP Version: 4.4.4
New Comment:
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);
?>
Previous Comments:
------------------------------------------------------------------------
[2006-09-22 11:16:53] 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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=38924&edit=1