Bug #79131 [NEW]: PDO does not throw an exception when parameter values are missing

From: Date: Thu, 16 Jan 2020 15:33:13 +0000
Subject: Bug #79131 [NEW]: PDO does not throw an exception when parameter values are missing
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224938@lists.php.net to get a copy of this message
From: love at sickpeople dot se Operating system: PHP version: 7.4.1 Package: PDO related Bug Type: Bug Bug description:PDO does not throw an exception when parameter values are missing Description: ------------ In the test script I execute the same statement three times. The last execution has two parameters but the second parameter has array key 2 instead of 1 and is thus missing. PDO returns false instead of throwing an exception. Note that emulated PREPARE must be disabled. Test script: --------------- $host = ''; $db = ''; $user = ''; $pass = ''; $options = [ PDO::ATTR_EMULATE_PREPARES => false, /* required */ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, ]; $pdo = new PDO("mysql:host=$host; dbname=$db; charset=utf8mb4", $user, $pass, $options); $stmt = $pdo->prepare('select ? a, ? b'); $set = [ ['a', 'b'], [0 => 'a', 1 => 'b'], [0 => 'a', 2 => 'b'], /* Note the array keys */ ]; foreach ($set as $params) { try { var_dump($stmt->execute($params), $stmt->fetchAll(PDO::FETCH_ASSOC)); } catch (Throwable $error) { echo $error->getMessage() . "\n"; } } Expected result: ---------------- If emulated PREPARE is enabled, an error "SQLSTATE[HY093]: Invalid parameter number: parameter was not defined" is issued. The same error should be thrown as an exception. Actual result: -------------- bool(true) array(1) { [0]=> array(2) { ["a"]=> string(1) "a" ["b"]=> string(1) "b" } } bool(true) array(1) { [0]=> array(2) { ["a"]=> string(1) "a" ["b"]=> string(1) "b" } } bool(false) array(0) { } -- Edit bug report at https://bugs.php.net/bug.php?id=79131&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79131&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79131&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79131&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79131&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79131&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79131&r=support Expected behavior: https://bugs.php.net/fix.php?id=79131&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79131&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79131&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79131&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79131&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79131&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79131&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79131&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79131&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79131&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79131&r=mysqlcfg

« previous php.bugs (#224938) next »