php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78152 PDO::exec() - Bad error handling with multiple commands
Submitted: 2019-06-12 20:32 UTC Modified: 2020-12-09 11:49 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: szijarto dot tamas dot developer at gmail dot com Assigned: nikic (profile)
Status: Closed Package: PDO MySQL
PHP Version: 7.3Git-2019-06-12 (Git) 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: szijarto dot tamas dot developer at gmail dot com
New email:
PHP Version: OS:

 

 [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






Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-15 12:37 UTC] 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!
 [2020-12-09 11:49 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-12-09 11:49 UTC] nikic@php.net
Fixed by https://github.com/php/php-src/commit/44b234a9bc589ee6c4afe3e1c386d536f750abe2. I referenced the wrong bug in the commit message.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC