|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-12-13 07:08 UTC] vicrry at yahoo dot com dot hk
Description:
------------
It seems the cursor didn't close after iterated through with foreach statement, but I don't insist any other causes.
I don't know if it is expected, but it really cause inconvenience and reduce readability to add a fetchAll() line after every query.
Reproduce code:
---------------
$Pdo = new PDO('mysql:host=localhost,dbname=test');
$res=$Pdo->query('SELECT * FROM TEST_TABLE');
foreach($res as $row) print_r($row);
$res=$Pdo->query('SELECT * FROM TEST_TABLE2');
foreach($res as $row) print_r($row);
Expected result:
----------------
Prints out each row in table 'TEST_TABLE' and 'TEST_TABLE2'.
Actual result:
--------------
The first query seems works fine, though it might have error info left unprinted.
The second query doesn't work at all, and the query() statement didn't even report an error.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 11:00:01 2025 UTC |
I found a simple solve for this error. Unset the PDOStatement object each time before your query again with the same variable. Reproduce code: --------------- $Pdo = new PDO('mysql:host=localhost,dbname=test'); $res=$Pdo->query('SELECT * FROM TEST_TABLE'); foreach($res as $row) print_r($row); unset($res); $res=$Pdo->query('SELECT * FROM TEST_TABLE2'); foreach($res as $row) print_r($row); --------------- But this seems to be a bug anyway, it DO causes inconveniences.