php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #36157 Introduce new PDO attribute to automatically close old statement.
Submitted: 2006-01-25 16:59 UTC Modified: 2021-09-10 16:31 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: fh at ez dot no Assigned: cmb (profile)
Status: Wont fix Package: PDO related
PHP Version: 5.1.2 OS: Gentoo Linux
Private report: No CVE-ID: None
 [2006-01-25 16:59 UTC] fh at ez dot no
Description:
------------
Currently when using the MySQL PDO driver, trying to 
execute a second statement while the first one is still 
active yields: 
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. 
 
This is all well and good, but quite unhandy since it is 
inconsistent with e.g the postgres driver that does not 
suffer from this problem. It also makes it very hard e.g 
wrap the result of an SQL statement in an iterator since 
the user might break out of it. 
 
I propose to introduce a new attribute to PDO that force 
the drivers to automatically "flush" any open statements 
when a new one is executed. 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-02 02:18 UTC] jani@php.net
-Package: Feature/Change Request +Package: PDO related
 [2021-09-09 12:32 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-09-09 12:32 UTC] cmb@php.net
Is this even still an issue with any of the actively supported PHP
versions[1]?

[1] <https://www.php.net/supported-versions.php>
 [2021-09-10 16:31 UTC] dharman@php.net
-Status: Feedback +Status: Wont fix
 [2021-09-10 16:31 UTC] dharman@php.net
I am declining this FR. Silent behaviours are not desirable. Automatically closing the previous statement sounds like a hack rather than a solution. The solution is already available as indicated by the error message you get. Use buffered mode or fetch all results into an array. 

The reason why it works differently than PostgreSQL is that mysqlnd and libmysqlclient offer unbuffered mode that doesn't fetch the results automatically from the server. This error can also occur when you are using stored procedures or multi-queries in which case closing the previous statement could cause unwanted consequences. 

If you feel strong enough about this feature, please submit a Pull Request on GitHub and create an RFC. 

@cmb Yes, this is still a problem with the current version.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC