Bug #78152 [Opn->Csd]: PDO::exec() - Bad error handling with multiple commands
Edit report at https://bugs.php.net/bug.php?id=78152&edit=1
ID: 78152
Updated by: nikic@php.net
Reported by: szijarto dot tamas dot developer at gmail dot com
Summary: PDO::exec() - Bad error handling with multiple
commands
-Status: Open
+Status: Closed
Type: Bug
Package: PDO MySQL
Operating System: Linux
PHP Version: 7.3Git-2019-06-12 (Git)
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Fixed by https://github.com/php/php-src/commit/44b234a9bc589ee6c4afe3e1c386d536f750abe2.
I referenced the wrong bug in the commit message.
Previous Comments:
------------------------------------------------------------------------
[2020-01-15 12:37:35] gvanbiemen at shopbox dot nl
Just experienced this behavior using the fragment below:
$pdo = new PDO('mysql:...');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec("SET @FOO = 'bar'"); // OK
$pdo->exec("SET @FOO = 'bar'; jadiejada"); // OK?!?
$pdo->exec("jadiejada"); // PDOException like expected
The second exec call should have thrown a PDOException!
------------------------------------------------------------------------
[2019-06-12 20:32:16] szijarto dot tamas dot developer at gmail dot com
Description:
------------
The PDO::exec() does not handle the error if the first command is successfully completed.
Environment:
=====================================================================
PHP : ~/php-install/bin/php
PHP_SAPI : cli
PHP_VERSION : 7.3.8-dev
ZEND_VERSION: 3.3.8-dev
PHP_OS : Linux - Linux ... 4.18.0-21-generic #22~18.04.1-Ubuntu SMP Thu May 16 15:07:19 UTC
2019 x86_64
INI actual : ~/php-install/lib/php.ini
More .INIs :
Test script:
---------------
/** @var PDO $db */
$res = $db->exec("INSERT INTO test(id, label) VALUES (41, 'x'); INSERT INTO
test_bad(id, label) VALUES (42, 'y')");
if( $res === false ){
print 'OK';
}
else{
var_dump($res);
print 'Failed, because the command ran!';
}
The full script is available here: https://github.com/szicsu/php-src/blob/PHP-7.3/ext/pdo_mysql/tests/pdo_mysql_exec_multi_command.phpt
The error message comes back from mysql but is not handled:
sendto(3, "_\0\0\0\3INSERT INTO test(id, label) VALUES (41, 'x'); INSERT INTO
test_bad(id, label) VALUES (42, 'y')", 99, MSG_DONTWAIT, NULL, 0) = 99
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 86400000) = 1 ([{fd=3, revents=POLLIN}])
recvfrom(3, "\7\0\0\1\0\1\0\n\0\0\0", 32768, MSG_DONTWAIT, NULL, NULL) = 11
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 86400000) = 1 ([{fd=3, revents=POLLIN}])
recvfrom(3, "/\0\0\2\377z\4#42S02Table 'php_src.test_bad' doesn't exist",
32768, MSG_DONTWAIT, NULL, NULL) = 51
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78152&edit=1
Thread (3 messages)