php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73878 PDOStatement::execute() throws a warning when ATTR_ERRMODE = ERRMODE_EXCEPTION
Submitted: 2017-01-06 07:17 UTC Modified: 2020-10-28 12:08 UTC
Votes:20
Avg. Score:4.5 ± 0.8
Reproduced:18 of 18 (100.0%)
Same Version:9 (50.0%)
Same OS:12 (66.7%)
From: alexander at dobrolyubov dot com Assigned: nikic (profile)
Status: Closed Package: PDO MySQL
PHP Version: 7.1.0 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alexander at dobrolyubov dot com
New email:
PHP Version: OS:

 

 [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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-19 16:25 UTC] bburnichon+php dot net at gmail dot com
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 */
}
```
 [2018-11-19 16:45 UTC] bburnichon+php dot net at gmail dot com
Several bugs looking the same to me:
https://bugs.php.net/bug.php?id=53185
https://bugs.php.net/bug.php?id=74401
https://bugs.php.net/bug.php?id=63812

Link to full codebase I was refering to in my previous comment https://github.com/php/php-src/blob/PHP-7.1.24/ext/mysqlnd/mysqlnd_wireprotocol.c#L298
 [2020-10-28 12:08 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-10-28 12:08 UTC] nikic@php.net
This should be fixed since PHP 7.4, by https://github.com/php/php-src/commit/2856afc70e50b85424b2bd2d6653020679160a0b.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 11:01:30 2024 UTC