Bug #36406 PHP/PDO randomly loses MySQL connection calling stored procedures several times
Submitted: 29 Apr 2008 17:17 Modified: 25 Aug 2010 12:36
Reporter: Markus Breyer Email Updates:
Status: Closed Impact on me:
None 
Category:Connectors: mysqlnd ( PHP ) Severity:S2 (Serious)
Version:Any up to 5.0.51 OS:Windows (WinXP SP2)
Assigned to: Andrey Hristov CPU Architecture:Any
Tags: Connection, lost, PDO, PDO_MySQL, PECL, php, stored procedure

[29 Apr 2008 17:17] Markus Breyer
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.
[29 Apr 2008 18:41] Sveta Smirnova
Thank you for the report.

But this seems to be bug in PDO_MYSQL really, because PDO_MYSQL does not properly support multiple result sets.
[25 Aug 2010 12:36] Ulf Wendel
http://bugs.php.net/bug.php?id=39858 has been marked as closed. Closing this one because it is a duplicate from the other bug system.