Bug #72368 [Opn]: PdoStatement->execute() fails but does not throw an exception
Edit report at https://bugs.php.net/bug.php?id=72368&edit=1
ID: 72368
Updated by: mbeccati@php.net
Reported by: fredrik at neam dot se
Summary: PdoStatement->execute() fails but does not throw an
exception
Status: Open
Type: Bug
-Package: PDO related
+Package: PDO MySQL
-Operating System: Debian Jessie
+Operating System: Any
PHP Version: 7.0.7
Block user comment: N
Private report: N
New Comment:
Moving to pdo_mysql as both pdo_sqlite and pdo_pgsql raise an exception, as expected. I haven't
tested the other drivers, but I will attach a patch that adds a PDO Common test for the issue.
Previous Comments:
------------------------------------------------------------------------
[2016-06-09 09:47:13] fredrik at neam dot se
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 this bug report at https://bugs.php.net/bug.php?id=72368&edit=1
Thread (6 messages)