|  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: 2015-09-16 10:31 UTC
Avg. Score:4.5 ± 0.8
Reproduced:54 of 54 (100.0%)
Same Version:9 (16.7%)
Same OS:8 (14.8%)
From: trebitzki at gmx dot net Assigned: mysql
Status: Not a bug Package: PDO MySQL
PHP Version: 5.3.10 OS: Mac OS X
Private report: No CVE-ID:
 [2012-04-03 22:57 UTC] trebitzki at gmx dot net
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();
$pdo_statement = $conn->prepare('SELECT 1; invalidstatement');

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

Actual result:
No error is thrown.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-11 15:08 UTC]
-Status: Open +Status: Feedback
 [2012-04-11 15:08 UTC]
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]
-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

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 but I don't 
why exactly. Could you explain me ?

 [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]
-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]
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?

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:

try {
	$statement = $pdo->prepare($sql);
	while ($statement->nextRowset()) {/* */};
} catch (\PDOException $e) {
	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
 [2015-09-16 10:23 UTC] col dot shrapnel at gmail dot com
Come on, close it as bogus already.
To get an exception one have to move over resultsets, using nextRowset(), which is the proper way, not a "workaround" as someone called it.
 [2015-09-16 10:31 UTC]
-Status: Assigned +Status: Not a bug
 [2015-09-16 10:31 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Since there are two statements and the first one is valid, you have to use nextRowset() and this is expected behavior.
 [2015-09-16 11:53 UTC] Daniel at Kraffner dot de
Even if this is considered "by design", the issue should be addressed in someway.
The current situation is inconsistent and quite a lot developers stumble across it, leading to the visible feedback within this bug report.

Why is an exception thrown right away, if a single statement is executed WITHOUT accessing the result set? Why does the result set needs to be accessed when multiple queries are executed? 

imho, the implementation should 

- either never throw an exception if the result set is NOT accessed, even if it is a single query.
- or always throw an exception without accessing the result set even for multiple queries.
 [2015-09-16 12:41 UTC] benjamin dot morel at gmail dot com
I don't think the current implementation is really a problem. But the documentation has to be clear about that, and the fact is, it isn't at the moment.
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Sun Nov 29 14:01:30 2015 UTC