mysql - PHP PDO multiple select query consistently dropping last rowset -


i'm experiencing appears bug using pdo statement make multiple selects.

i'm building sql query has many selects, , regardless of how many select statements makes, last rowset dropped.

here's truncated example of whats happening

$pdo = /* connection stuff here */ $sql = "select 1; select 2; select 3; select 4;"; $statement = $pdo->query($sql);  {     $rowset = $statement->fetchall();     if($rowset) {                        // stuff $rowset     }        } while($statement->nextrowset()); 

doing above, 1-3 retrieved rowsets, 4 not.
cannot explain why case. making subsequent queries same pdo object results in error:

pdo::query(): sqlstate[hy000]: general error: 2014 cannot execute queries while other unbuffered queries active.  consider using pdostatement::fetchall(). alternatively, if code ever going run against mysql, may enable query buffering setting pdo::mysql_attr_use_buffered_query attribute. 

the above do ... while ... routine based off of can found in php's documentation on nextrowset() function @ http://us1.php.net/manual/en/pdostatement.nextrowset.php

calling $statement->closecursor() @ end doesn't seem work

the routines i'm using more complex, can confirm sql behaves expected (by plugging mysql directly using phpmyadmin , running using mysqli->multi_query(), both of return expected results)

i found had similar issue , issued php bug ticket, apparently marked fixed: https://bugs.php.net/bug.php?id=61207&edit=1

can please explain me causing last rowset dropped? thanks!

versions: php 5.4.12, mysql 5.6.12

edit 1: attempted use mysql_attr_use_buffered_query changing code to...

$pdo = /* connection stuff here */ $pdo->setattribute(pdo::mysql_attr_use_buffered_query, true); // added code $sql = "select 1; select 2; select 3; select 4;"; $statement = $pdo->query($sql);  {     $rowset = $statement->fetchall();     if($rowset) {                        // stuff $rowset     }        } while($statement->nextrowset()); 

this didn't solve problem

i think on complicating things do/while loop.

try simple while loop instead:

$pdo = /* connection stuff here */ $sql = "select 1; select 2; select 3; select 4;"; $statement = $pdo->query($sql);  while($rowset = $statement->fetchall()){     //do stuff      $statement->nextrowset(); } 

this continue looping while rowset not have false value should work expect.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -