|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62847 PDO not released (or disconnect) if last query was error.
Submitted: 2012-08-17 17:14 UTC Modified: 2017-10-24 08:29 UTC
Avg. Score:4.5 ± 0.5
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:1 (25.0%)
From: softwareelves at gmail dot com Assigned:
Status: Verified Package: PDO related
PHP Version: 5.3.16 OS: OSX 10.8
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: softwareelves at gmail dot com
New email:
PHP Version: OS:


 [2012-08-17 17:14 UTC] softwareelves at gmail dot com
If PDO errors on it's LAST query it will refuse to disconnect from the database 
until the end of the script.

Test script:

$get_new_pdo = function() {
	return new PDO( ... );

$pdo1 = $get_new_pdo();
$pdo2 = $get_new_pdo();

$base_line = count( $pdo1->query( "SHOW PROCESSLIST;" )->fetchAll() );

$pdo2->query( "SELECT column FROM non_existent_table;" );
//$pdo2->query( "SELECT 1;" ); //uncommenting this line causes $pdo2 to be released correctly
$pdo2 = NULL;

$after_unset = count( $pdo1->query( "SHOW PROCESSLIST;" )->fetchAll() );

var_dump( $base_line - $after_unset );


Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-08 04:26 UTC] rgagnon24 at gmail dot com
Similar but different stuff happens under PHP5.4.14

It seems the PDOStatement object gets a reference to the PDO it was executed on, but when the PDOStatement errors or causes a PDOException (depending on the PDO::ATTR_ERROR_MODE), then the reference to the PDO object is not released, and you end up with a live database connection, but no way to close or control it.
 [2014-01-01 12:36 UTC]
-Package: PDO related +Package: PDO Core
 [2016-04-06 21:44 UTC] doug at opendns dot com
This is still reproducible in 5.6.19, and I can confirm that the attached test script still works (or, more accurately, doesn't work). Since PDO lacks an explicit disconnect method, this bug is kind of a pain.
 [2016-07-01 09:56 UTC]
There is already request #62065, which suggests to add a
disconnect() method. I don't mark this ticket as duplicate,
though, because this issue might be fixable without adding a new
 [2016-07-01 14:35 UTC]
-Status: Open +Status: Verified
 [2016-07-01 14:35 UTC]
Apparently, this issue has been resolved as of PHP 7.0.0 (tested
with 7.0.0 and 7.0.7 on Windows and current master on Linux).
 [2017-10-24 08:29 UTC]
-Package: PDO Core +Package: PDO related
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC