Edit report at https://bugs.php.net/bug.php?id=62065&edit=1
ID: 62065
Updated by: cmb@php.net
Reported by: b12 at bsdpower dot com
Summary: PDO should have a disconnect method
Status: Assigned
Type: Feature/Change Request
Package: PDO related
Operating System: Any
PHP Version: 5.3.13
Assigned To: willfitch
Block user comment: N
Private report: N
New Comment:
Related to doc bug #69730.
Previous Comments:
------------------------------------------------------------------------
[2016-04-06 21:33:39] doug at opendns dot com
Hey there,
I just wanted to add a vote for this feature, and also to note a connection to https://bugs.php.net/bug.php?id=62847, wherein
PDOStatement appears to hold onto a reference to the connection when a query error occurs. At that
point, setting the connection to null doesn't actually release the connection. In that case it
would be great to be able to manually force a disconnect.
------------------------------------------------------------------------
[2016-01-08 13:28:46] willfitch@php.net
Hi theunis.botha1@gmail.com.
Thanks for your input. While I agree the statements aren't the same, the conversation
wasn't about the syntax/reuse of the object, but rather closing a connection. I also agree
that a disconnect/close method is ideal while still allowing the reuse of the instance.
I will correct your statement: 'lets provide a connect() function but no disconnect()
function'. There is no connect() method, and the documentation clearly points out the intent
of connection handling: http://php.net/manual/en/pdo.connections.php.
Please remember this is an Open Source project and a large scale one at that. We aren't paid to
do this, have lives outside of our contributions, and have priorities with the many feature
requests/bugs reported on a daily basis.
If you feel strongly about this, you can definitely checkout the source, make the changes and
provide a pull request.
Thanks for bumping this ticket.
------------------------------------------------------------------------
[2016-01-08 09:46:16] theunis dot botha1 at gmail dot com
Dear willfitch@php.net
This is the MOST REDICULOUS statement I have ever seen :
"but in reality, is no different than a method call:
$dbh->close();
vs.
$dbh = null;
Both would achieve the same thing, but one is more attractive than the other."
These two statements ARE COMPLETELY DIFFERENT.
$dbh->close() would call into C or C++ or whichever language the WHOLE PDO MESS was written in,
allows you to re-use the $dbh object FROM PHP.
$dbh = null simply unsets the object in PHP and relies on the garbage collection mechanism (however
it is configured) to do the cleanup for you.
So I DO NOT KNOW in WHICH WORLD some person got the idea of : 'lets provide a connect()
function but no disconnect() function'
And $dbh = null IS SIMPLY NOT ELEGANT.
Please stop trying to BS everyone.
Provide a bloody disconnect() function for PDO and stop trying to convince everyone its not needed.
IT IS NEEDED.
Also, PDO persistent connections is the worst IDEA EVER.
------------------------------------------------------------------------
[2015-03-11 17:00:55] bpolaszek at gmail dot com
Hello,
Actually unset($pdo) or $pdo = null works well as soon as there aren't any PDOStatement object
initialized somewhere.
When working on prepared statements, unsetting the PDO instance has the following behaviour :
$pdo = new PDO([...]);
$stmt = $pdo->prepare("SELECT * FROM mytable WHERE mycolumn = :myvalue");
$stmt->bindValue(':myvalue', 'oh hi');
$stmt->execute();
$myvalue = $stmt->fetch(PDO::FETCH_COLUMN);
unset($myvalue); // $myvalue == null
unset($stmt); // $stmt == null
unset($pdo); // $pdo == null
sleep(30); // for 30 seconds, I can see the PDO connection is still alive on my MySql server,
despite $pdo is null. This wouldn't happen if I didn't prepare a statement.
Tested on PHP 5.3, PHP 5.4, PHP 5.5.
Do you plan a fix for this ? To avoid hundreds of sleeping connections while parsing big files, PHP
should really disconnect from the database when asked to.
------------------------------------------------------------------------
[2014-01-19 00:51:42] willfitch@php.net
Updated wrong ticket. My apologies. I am still looking into this.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=62065
--
Edit this bug report at https://bugs.php.net/bug.php?id=62065&edit=1