|  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: 2020-12-11 15:40 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: nikic (profile)
Status: Closed Package: PDO related
PHP Version: 5.3.16 OS: OSX 10.8
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
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
 [2020-12-11 15:40 UTC]
-Status: Verified +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-12-11 15:40 UTC]
Closing per previous comment by cmb.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Nov 28 21:03:16 2021 UTC