php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42499 PDO_MYSQL: multi-statement execution via PDO::exec() makes connection unusable
Submitted: 2007-08-31 16:00 UTC Modified: 2008-07-30 01:00 UTC
Votes:9
Avg. Score:4.4 ± 1.3
Reproduced:7 of 7 (100.0%)
Same Version:5 (71.4%)
Same OS:4 (57.1%)
From: suhachov at gmail dot com Assigned: johannes
Status: No Feedback Package: PDO related
PHP Version: 5.2.4 OS: FC
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-08-31 16:00 UTC] suhachov at gmail dot com
Description:
------------
$dbh = PDO('mysql:...',...);
$dbh->exec("SET some_var='value';SET names 'utf8'");
$dbh->query("SELECT NOW()");
# Error: Cannot execute queries while other unbuffered queries are active. ... 

PDO::MYSQL_ATTR_USE_BUFFERED_QUERY doesn't help.

I found that in mysql_handle_doer() multi-results aren't freed. 
I'm not a MySQL C API professional, but this patch seems to solve this problem:

--- php-5.1.6/ext/pdo_mysql/mysql_driver.c	2007-08-31 19:47:15.000000000 +0400
+++ php-5.1.6/ext/pdo_mysql/mysql_driver.c	2007-08-31 19:50:09.000000000 +0400
@@ -243,36 +243,20 @@
 
 static long mysql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRMLS_DC)
 {
-	int ret_val;
 	pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
 
 	if (mysql_real_query(H->server, sql, sql_len)) {
 		pdo_mysql_error(dbh);
-		ret_val = -1;
+		return -1;
 	} else {
-		//  !!
 		my_ulonglong c = mysql_affected_rows(H->server);
 		if (c == (my_ulonglong) -1) {
 			pdo_mysql_error(dbh);
-			ret_val =  (H->einfo.errcode ? -1 : 0);
+			return (H->einfo.errcode ? -1 : 0);
 		} else {
-			ret_val =  c;
-		}
+			return c;
 	}
-
-#if HAVE_MYSQL_NEXT_RESULT
-	while (mysql_more_results(H->server)) {
-		MYSQL_RES *res;
-		if (mysql_next_result(H->server) != 0) {
-			break;
 		}
-		res = mysql_store_result(H->server);
-		if (res) {
-			mysql_free_result(res);
-		}
-	}
-#endif
-	return ret_val;
 }
 
 static char *pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned int *len TSRMLS_DC)



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-03 09:15 UTC] jani@php.net
You report the bug with version 5.2.4, yet you seem to be using 5.1.6?!
How about you try with 5.2.4 first?
 [2007-09-03 18:58 UTC] suhachov at gmail dot com
How about _you_ check this issue instead of brushing aside?
This bug is reproduced with ANY versions of PHP (5.1.6 - 5.2.4)
 [2007-09-03 19:00 UTC] suhachov at gmail dot com
# tar xjf php-5.2.4.tar.bz2
# cd php-5.2.4
# ./configure --disable-all --with-pdo-mysql --enable-pdo --enable-cli --disable-cgi
# make
# sapi/cli/php -n pdo-mysql-bug.php 
Warning: PDO::query(): SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. in /home/andrew/src/php-5.2.4/pdo-mysql-bug.php on line 14
 [2007-09-04 10:36 UTC] jani@php.net
First of all: Check your tone. You're not dealing with people who get paid for reading insults and/or aggressive tone. That is the best way to get your report totally ignored. If I had "brushed aside" this report, I wouldn't have bothered writing anything, this would be bogus right now..

Patches are more than welcome but we'd like to get them as files (this bug system sucks, I know) so provide an url to the unified diff. And make the patch against latest CVS snapshot rather than release, it's lot easier to review and apply it then.

 [2007-09-04 14:42 UTC] suhachov at gmail dot com
I said it _only_ in reply to your response:
> You report the bug with version 5.2.4, yet you seem to 
> be using 5.1.6?!
> How about you try with 5.2.4 first?

I mentioned in this issue, that it applies to 5.2.4 and usually it means something (unless reporter is insane). I spent a lot of time to find this peace of code inside PDO and find out how to work it around  but you even didn't look to the source file to see that it wasn't changed since 5.1.X.

I know you guys aren't paid for this, but we aren't paid for tracing bugs too. So lets respect each others efforts ...

> so provide an url to the unified diff
http://blog.ru/php-pdo-multi-result.patch

> And make the patch against latest CVS snapshot rather than 
> release, it's lot easier to review and apply it then.

ok, but this patch is release-independent, this area is unchanged for a long time.
 [2007-09-04 14:45 UTC] jani@php.net
Andrey, can you check this out please. (or reassing to whoever is supposed to be maintaining ext/pdo_mysql :)

 [2008-04-05 21:06 UTC] mgrdinic at sledxchange dot com
Any movement here?
 [2008-04-29 14:43 UTC] kingoleg at mail dot ru
Hi, All

Is there any solution for this?
 [2008-05-22 19:53 UTC] uw@php.net
Should be fixed with the next release of PDO_MYSQLND
 [2008-07-22 14:40 UTC] uw@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.3-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.3-win32-installer-latest.msi

Please make sure that you try this with PHP 5.3+ and mysqlnd (--with-pdo-mysql=mysqlnd , default). It might not work when using the mysqlclient library (libmysql, --with-pdo-mysql=/path/to/mysql_config)
 [2008-07-30 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2008-11-05 09:21 UTC] stormi at laposte dot net
This is still valid in php 5.2.6
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Mon Apr 21 14:02:18 2014 UTC