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: 2018-03-06 10:59 UTC
Votes:60
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:
Status: Not a bug Package: PDO MySQL
PHP Version: 5.3.10 OS: Mac OS X
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: trebitzki at gmx dot net
New email:
PHP Version: OS:

Further comment on this bug is unnecessary.

 

 [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

Pull Requests

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
 [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] tony2001@php.net
-Status: Assigned +Status: Not a bug
 [2015-09-16 10:31 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

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.
 [2018-03-06 10:45 UTC] phpbug at braten dot be
This bug should be reopened.

It really is a problem when you have several DELETE statements and/or UPDATE statments. It happend to me yesterday that the 3rd DELETE statment had a bug, and I could not figure out why the records where still there in my database. No exceptions where thrown.

Does using nextRowset() even work when you are using multiple DELETE statements?
 [2018-03-06 10:49 UTC] spam2 at rhsoft dot net
just don't place multiple statements in a single query and then wonder why debug it don't work that well - it's that easy
 [2018-03-06 10:55 UTC] phpbug at braten dot be
I had to abandon using the "feature" of multiple sql statements in one query because of this.

So yes, because the feature is buggy, the "simple" solution is not to use it.

But I think it is wrong to leave this as a buggy feature that can't be really used.
 [2018-03-06 10:59 UTC] requinix@php.net
-Assigned To: mysql +Assigned To: -Block user comment: No +Block user comment: Yes
 [2018-03-06 10:59 UTC] requinix@php.net
As was explained years ago, this is NOT A BUG. If you execute multiple queries then you need nextRowset() to look at the results from each one. That is how it is supposed to work.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 07 11:01:28 2024 UTC