php.net |  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
Votes:4
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
 [2012-08-17 17:14 UTC] softwareelves at gmail dot com
Description:
------------
If PDO errors on it's LAST query it will refuse to disconnect from the database 
until the end of the script.

Test script:
---------------
<?php

$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:
----------------
int(1)

Actual result:
--------------
int(0)

Patches

Pull Requests

History

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] felipe@php.net
-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] cmb@php.net
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
method.
 [2016-07-01 14:35 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2016-07-01 14:35 UTC] cmb@php.net
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] kalle@php.net
-Package: PDO Core +Package: PDO related
 [2020-12-11 15:40 UTC] nikic@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-12-11 15:40 UTC] nikic@php.net
Closing per previous comment by cmb.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC