php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61207 PDO::nextRowset() after a multi-statement query doesn't always work
Submitted: 2012-02-29 05:45 UTC Modified: 2012-03-05 23:38 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: acabal at ucla dot edu Assigned: mysql (profile)
Status: Closed Package: PDO related
PHP Version: 5.4.0RC8 OS: Ubuntu 11.10 64-bit
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: acabal at ucla dot edu
New email:
PHP Version: OS:

 

 [2012-02-29 05:45 UTC] acabal at ucla dot edu
Description:
------------
After executing a single multi-statement query in PDO in which the statements are INSERT, followed by UPDATE, followed by SELECT, then trying to loop over the results using PDO::nextRowset(), the function returns FALSE (i.e. no more rowsets) after the UPDATE rowset, but before reaching the SELECT rowset.  Thus the SELECT rowset is lost.

I tried several permutations of multi-statement queries.  INSERT, then SELECT, then UPDATE works; SELECT then UPDATE works; UPDATE then SELECT works; only INSERT, then UPDATE, then SELECT fails.

See the below code for those examples plus the bugged example.

I originally ran in to this problem on PHP 5.3.5, but it still appears in PHP 5.4.0RC8.

Test script:
---------------
First create the following MySQL test db/table:


create database `test`character set utf8 collate utf8_general_ci;
create table `test`.`testtable`( `id` int ); 


Next check this example code to see the bug in action.  There are four examples in the code, the first three work, and the last one is the bug.

http://pastebin.com/EKePD6e2

The bug tracker suggested a link for code longer than 20 lines, though I can provide the example script directly in this bug report if that would be helpful.

Expected result:
----------------
Handle 1:
Rowset 1
Rowset 2
Results detected
Handle 2:
Rowset 1
Results detected
Handle 3:
Rowset 1
Rowset 2
Results detected
Handle 4:
Rowset 1
Rowset 2
Results detected

Actual result:
--------------
Handle 1:
Rowset 1
Rowset 2
Results detected
Handle 2:
Rowset 1
Results detected
Handle 3:
Rowset 1
Rowset 2
Results detected
Handle 4:
Rowset 1

Patches

bug61207.diff (last revision 2012-02-29 12:21 UTC by johannes@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-29 05:57 UTC] acabal at ucla dot edu
Oops, a small typo in the linked example script: In the bugged example, I typed $handle1 instead of $handle4 in the do loop.  Interestingly the script still produces the same bugged output even with the typo.
 [2012-02-29 12:21 UTC] johannes@php.net
The following patch has been added/updated:

Patch Name: bug61207.diff
Revision:   1330518108
URL:        https://bugs.php.net/patch-display.php?bug=61207&patch=bug61207.diff&revision=1330518108
 [2012-02-29 12:22 UTC] johannes@php.net
The attached patch should fix it, but needs some tests for PDO weirdness.
 [2012-02-29 12:22 UTC] johannes@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: mysql
 [2012-03-05 23:38 UTC] johannes@php.net
Automatic comment from SVN on behalf of johannes
Revision: http://svn.php.net/viewvc/?view=revision&revision=323928
Log: Fix Bug #61207 PDO::nextRowset() after a multi-statement query doesn't always work
 [2012-03-05 23:38 UTC] johannes@php.net
-Status: Assigned +Status: Closed
 [2012-03-05 23:38 UTC] johannes@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-04-18 09:45 UTC] laruence@php.net
Automatic comment on behalf of johannes
Revision: http://git.php.net/?p=php-src.git;a=commit;h=5c896b344a761c597a2decda14e25375f3b69ef3
Log: Fix Bug #61207 PDO::nextRowset() after a multi-statement query doesn't always work
 [2012-07-24 23:36 UTC] rasmus@php.net
Automatic comment on behalf of johannes
Revision: http://git.php.net/?p=php-src.git;a=commit;h=5c896b344a761c597a2decda14e25375f3b69ef3
Log: Fix Bug #61207 PDO::nextRowset() after a multi-statement query doesn't always work
 [2013-11-17 09:33 UTC] laruence@php.net
Automatic comment on behalf of johannes
Revision: http://git.php.net/?p=php-src.git;a=commit;h=5c896b344a761c597a2decda14e25375f3b69ef3
Log: Fix Bug #61207 PDO::nextRowset() after a multi-statement query doesn't always work
 [2014-05-16 17:02 UTC] norbert at linuxnetworks dot de
The fix might have introduced another problem. Executing a SQL query with multiple select statements won't return two result sets:

select * from testtable; select * from testtable

It also doesn't matter if both statements are the same. This SQL string doesn't work also:

select * from testtable; select * from testtable where 1

PHP 5.3.10 works fine, later versions up to 5.3.27 won't. The result using PHP 5.4.27 and 5.5.11 is also OK and both result sets are returned.
 [2022-06-15 09:23 UTC] biagiopas at yahoo dot it
$statement = $connection->query($sql_multiquery);

//check for errors
do { } while ($statement->nextRowset());
I noticed that $statement->nextRowset() closes the current transaction, so if something went wrong you can't rollBack
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC