php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50318 multiple statments result exception
Submitted: 2009-11-28 12:08 UTC Modified: 2010-10-28 09:40 UTC
From: yury at nix dot co dot il Assigned: mysql (profile)
Status: Not a bug Package: PDO related
PHP Version: 5.2.11 OS: FreeBSD 7.2-STABLE
Private report: No CVE-ID: None
 [2009-11-28 12:08 UTC] yury at nix dot co dot il
Description:
------------
When using multiple statments in a single $pdo->execute(),
php throws an exception, however the staments bieng executed anyway.
( example: http://pastebin.com/f6aec645c )

I think the mysql server expects the resultset to be advanced even if it's empty, as shown in the c-api example here:
http://dev.mysql.com/doc/refman/5.1/en/c-api-multiple-queries.html

I think the follwing will resolve the issue
( diff against svn 5_2 )
*** mysql_driver.c      Sat Nov 28 13:13:07 2009
--- /home/yury/php-5.2.11/ext/pdo_mysql/mysql_driver.c  Fri Nov 27 13:55:46 2009
***************
*** 252,261 ****
--- 252,262 ----
                my_ulonglong c = mysql_affected_rows(H->server);
                if (c == (my_ulonglong) -1) {
                        pdo_mysql_error(dbh);
                        return (H->einfo.errcode ? -1 : 0);
                } else {
+                       while ( 0 == mysql_next_result( H->server ) );
                        return c;
                }
        }
  }


Reproduce code:
---------------
http://pastebin.com/f6aec645c

Expected result:
----------------
throw exception and not commit
-or-
commit and not throw exception

Actual result:
--------------
The follwing exception thrown:

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.

But the data IS commited to the database.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-28 12:18 UTC] yury at nix dot co dot il
I have just checked out the code of mysql_driver.c in 5_3,
it seems that the issue handled there, however I do not understand why to
mysql_store_result() and then mysql_free_result(), it seems to work with my solution as well... ( checked only on 5.2.11 )
 [2010-10-28 09:40 UTC] uw@php.net
-Status: Assigned +Status: Bogus
 [2010-10-28 09:40 UTC] uw@php.net
PHP 5.2 is EOL'd. Use PHP 5.3

http://www.php.net/archive/2010.php#id2010-07-22-1

 The PHP development team would like to announce the immediate availability of PHP 5.2.14. This release focuses on improving the stability of the PHP 5.2.x branch with over 60 bug fixes, some of which are security related.

This release marks the end of the active support for PHP 5.2. *Following this release the PHP 5.2 series will receive no further active bug maintenance.* Security fixes for PHP 5.2 might be published on a case by cases basis. All users of PHP 5.2 are encouraged to upgrade to PHP 5.3
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 14:01:29 2024 UTC