phpdoctrinedqldoctrine-1.2

How to fetch results one by one in Doctrine 1.2?


How can I make something similar to classic PHP PDO

while ($obj = $stmt->fetch()) {...}

in Doctrine 1.2.

I've tried

while ($obj = $query->fetchOne()) {...} 

but it returns always only the first object found.

Is there any way I could implement this behaviour?

Doesn't really matter my query. It's a plain simple one (note that I am in the *Table class of the model)

$query = $this->createQuery('a');

Solution

  • Have you tried:

    while ($obj = $query->execute()) {...}
    

    And if you want to fetch an array instead of objects:

    while ($obj = $query->execute(array(), Doctrine_Core::HYDRATE_ARRAY)) {...}