#43586 [Opn]: Unable to query again after foreach on MySQL

From: Date: Tue, 18 Dec 2007 15:17:58 +0000
Subject: #43586 [Opn]: Unable to query again after foreach on MySQL
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-120741@lists.php.net to get a copy of this message
ID: 43586 Updated by: msaraujo@php.net Reported By: vicrry at yahoo dot com dot hk Status: Open Bug Type: PDO related Operating System: Linux PHP Version: 5.2.5 New Comment: Hello, Can you please send me your SQL definition for TEST_TABLE and TEST_TABLE2? Previous Comments: ------------------------------------------------------------------------ [2007-12-13 07:08:36] 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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43586&edit=1

« previous php.bugs (#120741) next »