|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-06-12 20:32 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 15:00:01 2025 UTC |
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!