|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 13:00:02 2025 UTC |
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); ?>