From:             suhachov at gmail dot com
Operating system: FC
PHP version:      5.2.4
PHP Bug Type:     PDO related
Bug description:  After multi-statement execution via PDO::exec() connection 
becomes unusable

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)



-- 
Edit bug report at http://bugs.php.net/?id=42499&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42499&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42499&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42499&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42499&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42499&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42499&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42499&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42499&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42499&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42499&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42499&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42499&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42499&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42499&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42499&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42499&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42499&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42499&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42499&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42499&r=mysqlcfg

Reply via email to