Bug #53185 [Asn->Opn]: PDO_MYSQL constructor, PHP warning w/ Exception error mode
| From: | kalle@php.net | Date: | Sun, 31 Jul 2016 04:25:17 +0000 |
| Subject: | Bug #53185 [Asn->Opn]: PDO_MYSQL constructor, PHP warning w/ Exception error mode | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-202750@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=53185&edit=1
ID: 53185
Updated by: kalle@php.net
Reported by: alexc223 at googlemail dot com
Summary: PDO_MYSQL constructor, PHP warning w/ Exception
error mode
-Status: Assigned
+Status: Open
Type: Bug
Package: PDO MySQL
Operating System: Linux
PHP Version: 5.3.3
-Assigned To: kalle
+Assigned To:
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2015-02-03 17:26:37] tom dot castleman at b3-it dot com
This error is present in 5.6.4.
PDO::__construct emits an E_WARNING despite passing PDO::ATTR_ERRMODE option to it:
$pdo = new PDO('mysql:host=foo;dbname=bar', 'user', 'pass',
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
Expected Result:
----------------
PDOException - MySQL server has gone away
Actual Result:
--------------
E_WARNING: PDO::__construct(): MySQL server has gone away
------------------------------------------------------------------------
[2014-12-15 10:28:35] s dot adrichem at daisycon dot com
In php 5.3.23 this did not happen upon disconnects and such, eventough we never set the mode, now
though in PHP 5.6.3 it does happen even if we change the modes, with the following simple code.
$sHostName = "";
$sUserName = "";
$sPassword = "";
$sDefaultDb = "";
$sTestQuery = " SELECT NOW()";
$iPort = 3306;
$oDb = new PDO(
'mysql:host='.$sHostName.';port=' . $iPort,
$sUserName,
$sPassword
);
$oDb->setAttribute(
PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION
);
var_dump($oDb->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_EXCEPTION);
$sQuery = "SET WAIT_TIMEOUT = 1";
$oResult = $oDb->prepare( $sQuery );
$oResult->execute();
$sQuery = "use " . $sDefaultDb;
$oResult = $oDb->prepare( $sQuery );
$oResult->execute();
sleep(3);
$oResult = $oDb->prepare( $sTestQuery );
$oResult->execute();
while ($aRow = $oResult->fetch( PDO::FETCH_ASSOC ))
{
var_dump($aRow);
}
I get the following warnings:
Warning: PDOStatement::execute(): MySQL server has gone away in pdotest.php on line 31
Warning: PDOStatement::execute(): Error reading result set's header in pdotest.php on line 31
And then the expected exception
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General
error: 2006 MySQL server has gone away' in pdotest.php on line 31
Same goes for silent mode, so whats the point of these modes then ;)
------------------------------------------------------------------------
[2012-06-24 10:15:44] pineain at gmail dot com
Same problem on Windows 7 x64
------------------------------------------------------------------------
[2012-05-15 11:37:54] jach at wayf dot dk
Same error on OSX version 3.5.10
------------------------------------------------------------------------
[2010-12-22 17:19:46] alexc223 at googlemail dot com
Maybe there needs to be a way for it to know? Either way, it's highly annoying
since there is very little ways to handle it.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=53185
--
Edit this bug report at https://bugs.php.net/bug.php?id=53185&edit=1