Bug #73878 [Com]: PDOStatement::execute() throws a warning when ATTR_ERRMODE = ERRMODE_EXCEPTION

From: Date: Mon, 19 Nov 2018 16:45:55 +0000
Subject: Bug #73878 [Com]: PDOStatement::execute() throws a warning when ATTR_ERRMODE = ERRMODE_EXCEPTION
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218051@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73878&edit=1

 ID:                 73878
 Comment by:         bburnichon+php dot net at gmail dot com
 Reported by:        alexander at dobrolyubov dot com
 Summary:            PDOStatement::execute() throws a warning when
                     ATTR_ERRMODE = ERRMODE_EXCEPTION
 Status:             Open
 Type:               Bug
 Package:            PDO MySQL
 Operating System:   Linux
 PHP Version:        7.1.0
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2018-11-19 16:25:50] 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 */
}
```

------------------------------------------------------------------------
[2017-01-06 07:17:10] 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



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=73878&edit=1


Thread (1 message)

  • bburnichon+php dot net at gmail dot com
  • Unknown Message
    • bburnichon+php dot net at gmail dot com
« previous php.bugs (#218051) next »