|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-03-09 17:32 UTC] shyandsy at gmail dot com
Description:
------------
The PDO shows warning event I have set the error mode to exception
Test script:
---------------
<?php
define(DB_HOSTNAME, "");
define(DB_PORT, "");
define(DB_DATABASE, "");
define(DB_USERNAME, "");
define(DB_PASSWORD, "");
echo DB_HOSTNAME . "\n";
try{
$dsn = "mysql:host=" . DB_HOSTNAME. ";port=" . DB_PORT . ";dbname=" . DB_DATABASE;
$pdo = new PDO($dsn,DB_USERNAME,DB_PASSWORD, [
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
$pdo->query("SET wait_timeout=1;");
sleep(3);
$pdo->query("select * from dev_user");
}catch(\PDOException $e){
echo $e->getMessage() . "<br>";
}
Expected result:
----------------
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
Actual result:
--------------
[root@localhost experiment]# php MysqlGoneAway.php
192.168.216.133
PHP Warning: PDO::query(): MySQL server has gone away in /home/wwwroot/www.xxx.com/experiment/MysqlGoneAway.php on line 21
PHP Warning: PDO::query(): Error reading result set's header in /home/wwwroot/www.xxx.com/experiment/MysqlGoneAway.php on line 21
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 02:00:01 2025 UTC |
1. I checked the output of php -m, yeah I m using mysqlnd. 2. This error can be catched by error handler, like following: ``` set_error_handler(function($code, $message, $file, $line) use($log, $config) { // 单独处理mysql gone away if(strpos($message, 'server has gone away') !== false){ return false; } ........ ``` 3. I checked the source code of mysqlnd, looks you are right it's just inconsistant to issue a warning if I set the error mode to exception