Req #36157 [Fbk->Wfx]: Introduce new PDO attribute to automatically close old statement.

From: Date: Fri, 10 Sep 2021 16:31:51 +0000
Subject: Req #36157 [Fbk->Wfx]: Introduce new PDO attribute to automatically close old statement.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236529@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=36157&edit=1

 ID:                 36157
 Updated by:         dharman@php.net
 Reported by:        fh at ez dot no
 Summary:            Introduce new PDO attribute to automatically close
                     old statement.
-Status:             Feedback
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            PDO related
 Operating System:   Gentoo Linux
 PHP Version:        5.1.2
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2021-09-09 12:32:13] 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>

------------------------------------------------------------------------
[2006-01-25 16:59:30] 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. 



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=36157&edit=1


Thread (4 messages)

« previous php.bugs (#236529) next »