From:             jpokotilow at tuneteller dot com
Operating system: Mac OS X 10.4.8
PHP version:      5.2.0
PHP Bug Type:     PDO related
Bug description:  Can't iterate over a PDOStatement object using foreach()

Description:
------------
I invoke PDO::query() twice, with two different valid 
SQL queries from within a class method. (Note: I make sure to 
invoke fetchAll() on the PDOStatement object returned by the 
first invocation before invoking PDO::query() a second time. 
Update: I just found out that if I set the first PDOStatement 
object to NULL, everything works as intended. HOWEVER, 
invoking fetchAll() should suffice, should it not?) I return 
the PDOStatement object generated by the second PDO::query() 
invocation. I'm unable to iterate over the object with a 
foreach() construct even though there ought to be results. 
Invoking fetchAll() on the object returns an empty array.

If I set the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute to 
true, I don't have this problem, but I'm pretty sure I 
shouldn't have it either way.

Reproduce code:
---------------
http://pastebin.com/825493

Expected result:
----------------
I expect to be able to iterate over rows associated with 
$broken_iterable_results ... or I would expect for 
$broken_iterable_results->fetchAll() to return rows associated 
with the PDOStatement object. At the very least, I expect for 
some error to be generated if I'm doing anything wrong.

Note: With PDO::ERRMODE_EXCEPTION set to true, there is an 
exception thrown.

Actual result:
--------------
Iterating over $broken_iterable_results results does nothing. 
Invoking $broken_iterable_results->fetchAll() returns an 
empty array.

-- 
Edit bug report at http://bugs.php.net/?id=39527&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=39527&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=39527&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=39527&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=39527&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=39527&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=39527&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=39527&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=39527&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=39527&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=39527&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=39527&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=39527&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=39527&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=39527&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=39527&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=39527&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=39527&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=39527&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=39527&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=39527&r=mysqlcfg

Reply via email to