Doc #69730 [NEW]: PDO: incorrect description of how to close the connection to the database
| From: | 37xzxz at gmail dot com | Date: | Fri, 29 May 2015 11:28:36 +0000 |
| Subject: | Doc #69730 [NEW]: PDO: incorrect description of how to close the connection to the database | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-12377@lists.php.net to get a copy of this message | ||
From: 37xzxz at gmail dot com
Operating system:
PHP version: 5.6.9
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:PDO: incorrect description of how to close the connection to the database
Description:
------------
---
From manual page: http://www.php.net/pdo.connections
---
I can't find bug about what cappytoi wrote in his comment
https://php.net/manual/en/pdo.connections.php#114822
"You shouldn't expect that your connection is closed when you set $dbh =
null unless all you do is just instantiating PDO class."
$stmt = null; // doing this is mandatory for connection to get closed
In fact this works if you use PDO::prepare and PDOStatement::execute.
If you use direct PDO::query and query contain some error "$stmt =
null;" also doesn't close the connection.
Test script:
---------------
<?php
$pdo = new PDO(
'mysql:host=localhost;port=3306;dbname=world',
'user',
'password'
);
try {
$stmt = $pdo->query('SELECT * FROM city1nonexisttable');
} catch (PDOException $e) {
$errorText = $e->getMessage();
var_dump($errorText);
}
$stmt = null;
$pdo = null;
sleep(10);
?>
Expected result:
----------------
The connection to the database will be closed after $pdo = null; as
described in documentation.
Actual result:
--------------
The connection to the database remains active after $pdo = null; and
hangs 10 seconds.
--
Edit bug report at https://bugs.php.net/bug.php?id=69730&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69730&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69730&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69730&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69730&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69730&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69730&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69730&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69730&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69730&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69730&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69730&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69730&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69730&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69730&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69730&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69730&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69730&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69730&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69730&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69730&r=mysqlcfg