Click to See Complete Forum and Search --> : [RESOLVED] PDOStatement


dougal85
01-27-2007, 02:10 PM
When you use a PDO object and do a query, it returns a PDOStatement Object.

However, What I don't understand is, if you do print_r($s) ($r being the pdostatement) It prints out like an object, with no sign of a result.

However, you can do a foreach() on the object and loop through your results.

Can somebody explain to me whats going on?

I just wanted to do a print_r and view the array... nice and simple for testing. How can i do this?

dougal85
01-27-2007, 02:33 PM
found it :) silly me

http://uk2.php.net/manual/en/function.pdostatement-fetchall.php

dream.scape
01-29-2007, 10:58 AM
However, you can do a foreach() on the object and loop through your results.

Can somebody explain to me whats going on?

To backup to this part of the question, I'm guessing that PDOStatement implements an iterator interface. Iterators were introduced in PHP 5, which allow you to iterate over an object using foreach(), and several of the new classes implement them. SimpleXML is another one that has an iterator (in addition to other new things like array access).

dougal85
01-29-2007, 04:19 PM
Cool, thanks.

I don't really understand that method, or how you would recreate it in an object. but now I know what to read up on. Thanks :)