|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-01-06 07:17 UTC] alexander at dobrolyubov dot com
Description:
------------
In php 7.1 the mysqlnd driver generates a warning "2006 MySQL server has gone away", but it should not as PDO::ATTR_ERRMODE set to PDO::ERRMODE_EXCEPTION
Test script:
---------------
<?php
$dbh = new PDO('mysql:dbname=testdb;host=localhost', 'testuser', 'testpwd');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
$dbh->exec('SET session wait_timeout=1');
sleep(2);
$stmt = $dbh->prepare('DO 1');
$stmt->execute();
Expected result:
----------------
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away in /home/dag/src/php-7.1.0/test.php:12
Stack trace:
#0 /home/dag/src/php-7.1.0/test.php(12): PDOStatement->execute()
#1 {main}
thrown in /home/dag/src/php-7.1.0/test.php on line 12
Actual result:
--------------
Warning: PDOStatement::execute(): MySQL server has gone away in /home/dag/src/php-7.1.0/test.php on line 12
Warning: PDOStatement::execute(): Error reading result set's header in /home/dag/src/php-7.1.0/test.php on line 12
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away in /home/dag/src/php-7.1.0/test.php:12
Stack trace:
#0 /home/dag/src/php-7.1.0/test.php(12): PDOStatement->execute()
#1 {main}
thrown in /home/dag/src/php-7.1.0/test.php on line 12
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 20:00:01 2025 UTC |
Actually, the error can be drilled down to mysqlnd driver which trigger warnings on its own. I think mysqlnd should have a configuration to avoid triggering warnings in these cases. Error is already saved in error_info from what I understand from the code. In mysqlnd_wireprotocol.c for example: ```C /* {{{ mysqlnd_read_packet_header_and_body */ static enum_func_status mysqlnd_read_packet_header_and_body(MYSQLND_PACKET_HEADER * packet_header, MYSQLND_PFC * pfc, MYSQLND_VIO * vio, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info, MYSQLND_CONNECTION_STATE * connection_state, zend_uchar * buf, size_t buf_size, const char * const packet_type_as_text, enum mysqlnd_packet_type packet_type) { DBG_ENTER("mysqlnd_read_packet_header_and_body"); DBG_INF_FMT("buf=%p size=%u", buf, buf_size); if (FAIL == mysqlnd_read_header(pfc, vio, packet_header, stats, error_info)) { SET_CONNECTION_STATE(connection_state, CONN_QUIT_SENT); SET_CLIENT_ERROR(error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone); php_error_docref(NULL, E_WARNING, "%s", mysqlnd_server_gone); DBG_ERR_FMT("Can't read %s's header", packet_type_as_text); DBG_RETURN(FAIL); } /* 8<---------------- Snipped */ } ```