#38924 [NEW]: mssql_next_result returns FALSE on multiple Resultsets

Posted: 09-22-2006, 11:16 AM
From: info at benjamin-wilger dot de
Operating system: Windows
PHP version: 4.4.4
PHP Bug Type: MSSQL related
Bug description: mssql_next_result returns FALSE on multiple Resultsets

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 bug report at http://bugs.php.net/?id=38924&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38924&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38924&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38924&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=38924&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=38924&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=38924&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=38924&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=38924&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=38924&r=support
Expected behavior: http://bugs.php.net/fix.php?id=38924&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=38924&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=38924&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=38924&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38924&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=38924&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=38924&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=38924&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=38924&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=38924&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=38924&r=mysqlcfg
Reply With Quote

Responses to "#38924 [NEW]: mssql_next_result returns FALSE on multiple Resultsets"

fmk@php.net
Guest
Posts: n/a
 
#38924 [Opn->Bgs]: mssql_next_result returns FALSE on multiple Resultsets
Posted: 09-22-2006, 05:08 PM
ID: 38924
Updated by: fmk@php.net
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
Reply With Quote
 
LinkBack Thread Tools Search this Thread Display Modes
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
#24627 [Bgs]: feof always returns false sniper@php.net PHP Development 2 07-13-2003 08:46 AM
#24627 [Opn->Bgs]: feof always returns false elmicha@php.net PHP Development 1 07-13-2003 03:43 AM
#24627 [Bgs->Opn]: feof always returns false duerra at yahoo dot com PHP Development 0 07-13-2003 03:40 AM
#24627 [Com]: feof always returns false b_ulrich at t-online dot de PHP Development 0 07-12-2003 11:21 PM
#24627 [NEW]: feof always returns false duerra at yahoo dot com PHP Development 0 07-12-2003 11:08 PM