Bug #77716 [Fbk->Opn]: PDO show warning event the PDO::ERRMODE_EXCEPTION has been set

From: Date: Sat, 09 Mar 2019 19:26:07 +0000
Subject: Bug #77716 [Fbk->Opn]: PDO show warning event the PDO::ERRMODE_EXCEPTION has been set
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219898@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77716&edit=1 ID: 77716 User updated by: shyandsy at gmail dot com Reported by: shyandsy at gmail dot com Summary: PDO show warning event the PDO::ERRMODE_EXCEPTION has been set -Status: Feedback +Status: Open Type: Bug Package: PDO Core Operating System: CentOS 7.3.1611 PHP Version: 7.2.16 Block user comment: N Private report: N New Comment: u have to set these constant begin with DB_ before u g the code Previous Comments: ------------------------------------------------------------------------ [2019-03-09 18:02:10] danack@php.net I'm unable to reproduce this error. Please can you check that you are posting the exact script that shows the error. Running the code as posted, I get warnings about: PHP Warning: Use of undefined constant DB_HOSTNAME - assumed 'DB_HOSTNAME' (this will throw an Error in a future version of PHP) in /var/app/test.php on line 15 Fixing those errors I get a single error, that was caught in the exception block: SQLSTATE[HY000] [2002] No such file or directory i.e. the output looks different from what you posted and looks like the correct behaviour. For example, in your output you have "192.168.216.133" - but you have "define(DB_HOSTNAME, "");" in the code example. ------------------------------------------------------------------------ [2019-03-09 17:32:09] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77716&edit=1

« previous php.bugs (#219898) next »