Bug #78152 [Com]: PDO::exec() - Bad error handling with multiple commands

From: Date: Wed, 15 Jan 2020 12:37:35 +0000
Subject: Bug #78152 [Com]: PDO::exec() - Bad error handling with multiple commands
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224912@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78152&edit=1

 ID:                 78152
 Comment by:         gvanbiemen at shopbox dot nl
 Reported by:        szijarto dot tamas dot developer at gmail dot com
 Summary:            PDO::exec() - Bad error handling with multiple
                     commands
 Status:             Open
 Type:               Bug
 Package:            PDO MySQL
 Operating System:   Linux
 PHP Version:        7.3Git-2019-06-12 (Git)
 Block user comment: N
 Private report:     N

 New Comment:

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!


Previous Comments:
------------------------------------------------------------------------
[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)

« previous php.bugs (#224912) next »