php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79661 PDO::ATTR_PERSISTENT also accepts a string key
Submitted: 2020-06-01 15:13 UTC Modified: 2020-06-01 16:14 UTC
From: thebluewalrus at gmail dot com Assigned:
Status: Closed Package: PDO Core
PHP Version: 7.3.18 OS: Amazon Linux release 2 (Karoo)
Private report: No CVE-ID: None
 [2020-06-01 15:13 UTC] thebluewalrus at gmail dot com
Description:
------------
If 2 PDO connections are opened they seem to be merged.

If the first is using unbuffered and second using buffered the first results in a buffered return.

 If both connections are using unbuffered and the first connection is running the second connection returns:

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.


on the first call.


Issue produces on machines running 7.3.17 (OS Amazon Linux release 2 (Karoo)) and 7.1.33 (OS Red Hat Enterprise Linux Server release 7.3 (Maipo)).

Test script:
---------------
Case 1:

$db = new PDO("mysql:host=".$dbhost.";dbname=".$dbname, $dbuser, $dbpass, array(PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false));
$db_ub = new PDO("mysql:host=".$dbhost.";dbname=".$dbname, $dbuser, $dbpass, array(PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));
$stmt = $db->prepare('A QUERY THAT WILL EXCEED MEMORY LIMIT IF ALL ROWS RETURNED');
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
//should run out of memory
}

Case 2:

$db = new PDO("mysql:host=".$dbhost.";dbname=".$dbname, $dbuser, $dbpass, array(PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false));
$db_ub = new PDO("mysql:host=".$dbhost.";dbname=".$dbname, $dbuser, $dbpass, array(PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false));
$stmt = $db->prepare('A QUERY THAT WILL EXCEED MEMORY LIMIT IF ALL ROWS RETURNED');
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$stmt = $db_ub->prepare('select now()');
$stmt->execute();
}

Expected result:
----------------
$stmt should only have 1 row at a time and memory usage should be low

Actual result:
--------------
Usually results in PHP Fatal error:  Allowed memory size ... 

ini_set('memory_limit', can be used to get the script to run.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-01 15:31 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-06-01 15:31 UTC] cmb@php.net
Instead of setting PDO::ATTR_PERSISTENT to true, you can set it to
some arbitrary key; connections with different persistence keys
will be separate.  In your case, maybe use something like
'buffered' and 'unbuffered', respectively.
 [2020-06-01 15:44 UTC] thebluewalrus at gmail dot com
-Status: Feedback +Status: Assigned
 [2020-06-01 15:44 UTC] thebluewalrus at gmail dot com
Thanks. That worked, I think the documentation should be updated in this case. All documentation I've seen has it used as a boolean value.
 [2020-06-01 16:14 UTC] cmb@php.net
-Summary: 2 Connections with different buffer stats cant run +Summary: PDO::ATTR_PERSISTENT also accepts a string key -Status: Assigned +Status: Verified -Type: Bug +Type: Documentation Problem -Assigned To: cmb +Assigned To:
 [2020-06-01 16:14 UTC] cmb@php.net
Thanks for the quick feedback!
 [2020-06-01 16:14 UTC] cmb@php.net
-Package: PDO MySQL +Package: PDO Core
 [2020-06-02 08:42 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=d8567f0b1ac7071dfa5aba57df8318273cd445c3
Log: Fix #79661: PDO::ATTR_PERSISTENT also accepts a string key
 [2020-06-02 08:42 UTC] phpdocbot@php.net
-Status: Verified +Status: Closed
 [2020-06-02 14:35 UTC] phpdocbot@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=a65d8b253d70b155cac36c163bcc6cb7c147520e
Log: Fix #79661: PDO::ATTR_PERSISTENT also accepts a string key
 [2020-06-02 14:40 UTC] phpdocbot@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=17b35484706c2570b41473e39b948287b556e487
Log: Fix #79661: PDO::ATTR_PERSISTENT also accepts a string key
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Oct 30 20:01:24 2020 UTC