php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61613 No PDO error if first SQL statement of a group is valid.
Submitted: 2012-04-03 22:57 UTC Modified: 2014-09-29 16:34 UTC
Votes:59
Avg. Score:4.5 ± 0.8
Reproduced:53 of 53 (100.0%)
Same Version:9 (17.0%)
Same OS:8 (15.1%)
From: trebitzki at gmx dot net Assigned: mysql
Status: Assigned Package: PDO MySQL
PHP Version: 5.3.10 OS: Mac OS X
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-04-03 22:57 UTC] trebitzki at gmx dot net
Description:
------------
I am submitting a group of two SQL statements to PDO. The first is valid, the second has a syntax error. PDO should throw an exception but doesn't. It only throws an exception when the first statement is invalid.

Test script:
---------------
//[symfony 1.4 environment]
$conn = Propel::getConnection();
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo_statement = $conn->prepare('SELECT 1; invalidstatement');
$pdo_statement->execute();


Expected result:
----------------
I expect to have an error thrown since the group of statements has a syntax error.

Actual result:
--------------
No error is thrown.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-11 15:08 UTC] johannes@php.net
-Status: Open +Status: Feedback
 [2012-04-11 15:08 UTC] johannes@php.net
Which PDO driver are you using?
 [2012-04-11 23:27 UTC] trebitzki at gmx dot net
-Status: Feedback +Status: Open
 [2012-04-11 23:27 UTC] trebitzki at gmx dot net
I'm working on 1and1 server with PDO Driver for MySQL, client library version	5.1.49; locally on Mac with PDO Driver for MySQL Client API version mysqlnd 5.0.7-dev - 091210 - $Revision: 304625 $. Both environments show this issue.
 [2012-08-01 19:40 UTC] jonwage at gmail dot com
I am experiencing the same issue. Tested on 5.3.5 and 5.3.10 currently.
 [2012-08-02 01:17 UTC] aharvey@php.net
-Assigned To: +Assigned To: mysql
 [2012-08-28 22:09 UTC] angel dot koilov at gmail dot com
Same issue debian wheezy, php 5.4.4-4
 [2012-10-29 09:42 UTC] verger dot antoine at gmail dot com
Hi, 

I have the same issue on 5.4.6 on Ubuntu 12.04 and PDO_MYSQL 5.5.24.

Di you have any idea where it comes from ? I had a look at the source from PDO 
and also from MySQL C API but no clue and above all too hard to find the origin.

I saw that the issue has been assigned to mysql by aharvey@php.net but I don't 
why exactly. Could you explain me ?

Antoine
 [2012-11-04 05:19 UTC] invisiblexman2010 at gmail dot com
I have the same issue,
php 5.4.0, pdo_mysql 5.5.19, for Win64 (x86)
 [2013-05-08 12:50 UTC] danieldummy at hotmail dot com
issue also happened in MSSQL(PDO DBLib) on Ubuntu with PHP 5.4.14-1~precise+1
 [2013-12-31 10:40 UTC] michal dot kikta at gmail dot com
really annoying bug causing serious production hazards if we want to optimize by batching multiple queries 

is there any workaround except rewriting our database layer to mysqli or writing stored procedure on our mysql servers?
 [2014-01-01 12:39 UTC] felipe@php.net
-Package: PDO related +Package: PDO MySQL
 [2014-03-31 05:39 UTC] oleg dot nucer at gmail dot com
I have the same problem! In multiqueries PDO throws an error only for the first statement. And there is absolutely no difference what is going after... Please fix this problem, because it can lead to critical security holes or just hard-to-find bugs in web-applications.
I'm using PHP 5.6 and MySQL 5.6 on Windows 8 x64.
 [2014-07-16 13:32 UTC] benjamin dot morel at gmail dot com
Is anyone working on this problem? As mentioned above, it can lead to dangerous bugs as there's currently no way to know if all the queries have been successfully executed or not.
 [2014-09-24 15:32 UTC] rquadling@php.net
As the query contains multiple result sets, what is the response if you actually take a look at the next rowset using PDOStatement::nextRowSet() in conjunction with PDOStatement::errorInfo() / PDOStatement::errorCode()?
 [2014-09-24 16:38 UTC] benjamin dot morel at gmail dot com
@rquadling Genius!

Indeed, just tested it on a PDO configured to throw exceptions, and the PDOException is thrown as soon as nextRowSet() is called!

When it's configured to *not* throw exceptions, as you guessed, the error information becomes available with PDOStatement::getErrorInfo().

So there's no bug after all, the behaviour of PHP is perfectly fine, maybe we could just mention this on the PDO error handling page in the docs?

http://php.net/manual/en/pdo.error-handling.php

Thanks so much.
 [2014-09-29 16:34 UTC] trebitzki at gmx dot net
The test script I included in my original bug report for this issue was only a simple example. I actually had this issue with a set of SQL UPDATE statements, so showing how fetching rows and looping through result sets obviates this is not really addressing the issue. When my first update statement runs successfully I can't call nextrowset(); the statements just run one after the other. The problem with not getting error info for any following statement that may fail still stands. And I must say that I am very surprised and disappointed that noone in the php group is willing to come to grips with this - after more than 2 1/2 years!
 [2014-10-13 10:26 UTC] pesterhazy at gmail dot com
Though it is possible to run multiple statements using `mysqli::multi_query`, with PDO it just doesn't work. For example, if you exec() a string containing multiple INSERT statements, only the first statement will be executed. No exception is thrown (PHP 5.5.17, MySQL server 5.5.38).

This is a bug. Running multiple SQL statements is useful, among other things, for creating stored procedures.
 [2015-04-14 14:12 UTC] mikhail dot v dot gavrilov at gmail dot com
This bug still not fixed in PHP 5.6.7
Linux Fedora 21
 [2015-06-16 15:51 UTC] blaimi at blaimi dot de
I'm using this as workaround:

$pdo->beginTransaction();
try {
	$statement = $pdo->prepare($sql);
	$statement->execute();
	while ($statement->nextRowset()) {/* https://bugs.php.net/bug.php?id=61613 */};
	$pdo->commit();
} catch (\PDOException $e) {
	$pdo->rollBack();
	throw $e;
}
 [2015-08-02 09:19 UTC] fekiri_malek at hotmail dot com
i have the same problem with php 5.5.12 on windows 7 x86
 
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Mon Aug 31 17:01:28 2015 UTC