Bug #72368 [NEW]: PdoStatement->execute() fails but does not throw an exception
From: fredrik at neam dot se
Operating system: Debian Jessie
PHP version: 7.0.7
Package: PDO related
Bug Type: Bug
Bug description:PdoStatement->execute() fails but does not throw an exception
Description:
------------
PdoStatement->execute() fails but does not throw an exception when
supplying parameters to execute() whilst not using any placeholders in
the query.
Tested on PHP 7.0.7, 5.6.20 and HHVM 3.13.1
Test script:
---------------
$dbh = new PDO('###');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$params = [":bar" => 1];
$sql = "SELECT 1";
$stmt = $dbh->prepare($sql);
$result = $stmt->execute($params);
Expected result:
----------------
Either ->execute() should return true and the result set be populated,
or an exception should be thrown (like it does for the below case):
$dbh = new PDO('###');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$params = [":bar" => 1];
$sql = "SELECT :foo";
$stmt = $dbh->prepare($sql);
$result = $stmt->execute($params);
Actual result:
--------------
$result is false, but an exception is not thrown. The result set is
empty.
This is problematic since when the error mode is set to
PDO::ERRMODE_EXCEPTION, it is fair to assume that failed statements
results in thrown exceptions, so that the return variable must not be
checked after each usage of ->execute().
--
Edit bug report at https://bugs.php.net/bug.php?id=72368&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72368&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72368&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72368&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72368&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72368&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72368&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72368&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72368&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72368&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72368&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72368&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72368&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72368&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72368&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72368&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72368&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72368&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72368&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72368&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72368&r=mysqlcfg
Thread (6 messages)
- fredrik at neam dot se