|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65825 PDOStatement::fetch() does not throw exception on broken server connection
Submitted: 2013-10-03 11:15 UTC Modified: 2014-01-01 12:30 UTC
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: cf0hay at gmail dot com Assigned:
Status: Open Package: PDO MySQL
PHP Version: 5.5.4 OS: Hardened Gentoo Linux 64
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: cf0hay at gmail dot com
New email:
PHP Version: OS:


 [2013-10-03 11:15 UTC] cf0hay at gmail dot com
Using PDO with mysqlnd driver.

PDO instance was asked to throw exceptions, but calling fetch() after the TCP connection broke does not throw an exception, it just emits a warning instead, "Empty row packet body".

The server is located on a different computer on the network, cannot use unix socket to reach it.

Test script:
$conn = new PDO(
                PDO::ATTR_PERSISTENT => false,
                PDO::ATTR_EMULATE_PREPARES => false,
                PDO::ATTR_STRINGIFY_FETCHES => false,
                PDO::ATTR_AUTOCOMMIT => true,
                PDO::MYSQL_ATTR_INIT_COMMAND => "SET time_zone = '+00:00'",
                PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false,
                PDO::MYSQL_ATTR_DIRECT_QUERY => false,
                PDO::MYSQL_ATTR_FOUND_ROWS => false,

        $res = $conn->query("
            any query which gives back a lot of rows
        while($row = $res->fetch(PDO::FETCH_ASSOC)){
            //during this loop runs, terminate the connection with something, like iptables

Expected result:
PDOStatement::fetch() should throw an exception as the server connection has gone away (trying to do a new PDO::query() after does throw an exception with that error message).

Actual result:
The script above just emits a warning and finishes the loop returning false the very same way as if there were no more rows left from the query.


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-03 11:35 UTC] cf0hay at gmail dot com
The correct SQLSTATE would be HY000, 2013.
 [2014-01-01 12:30 UTC]
-Package: PDO related +Package: PDO MySQL
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC