Description:
This is actually a bug in PDO_mysql, but I am reporting this to you because it seems that no-one over at PECL cares to fix this bug which is around for more than two!!! years now and making MySQL look bad!!! Link to the open bugs in the PECL/PHP bug database:
http://pecl.php.net/bugs/bug.php?id=7976
http://bugs.php.net/bug.php?id=39858
The cause seems to be that PDO_mysql does not properly support multiple result sets. This bug could be related:
http://pecl.php.net/bugs/bug.php?id=12845
There appears to be a workaround which is tossing out PDO_MySQL and using PDO_ODBC instead, but that is a very poor "fix" - seems like switching from flaky MySQL technology to reliable Microsoft technology :-)
Thanks!
How to repeat:
(Sometimes consistent, sometimes intermittent - if it won't happen, just call it more often, only happens on Windows)
CREATE PROCEDURE `foo`()
BEGIN
SELECT 2 * 2;
END;
<?php
$Db = new PDO('mysql:host=localhost;dbname=test', 'root', '',
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'",
PDO::ATTR_PERSISTENT => true));
$Db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$Db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$Pdo = $Db->prepare('CALL foo()');
$Pdo->execute();
print_r($Pdo->fetchAll());
$Pdo = $Db->prepare('CALL foo()');
$Pdo->execute();
print_r($Pdo->fetchAll());
$Pdo->closeCursor();
?>
Expected result:
----------------
Array
(
[0] => Array
(
[2 * 2] => 4
)
)
Array
(
[0] => Array
(
[2 * 2] => 4
)
)
Actual result:
--------------
Array
(
[0] => Array
(
[2 * 2] => 4
)
)
<br />
<b>Warning</b>: PDOStatement::execute() [<a
href='function.PDOStatement-execute'>function.PDOStatement-execute</a>]:
SQLSTATE[HY000]: General error: 2013 Lost connection to MySQL server
during query in <b>C:\home\test\www\pdo.php</b> on line <b>12</b><br />
Array
(
)
Suggested fix:
Best known workaround so far is to toss out PDO_MySQL and use PDO_ODBC instead.