PHP/PDO: return query rows without foreach?

TrunseEveve

New Member
I am confused about this, I run a query such as \[code\]foreach($dbh->query("SELECT * FROM ...") as $row) { ...do something with row()\[/code\]But when I var_dump \[code\]$dbh\[/code\] it is a PDOstatement object.This leads me to two questions:
  • How does foreach somehow resolve the object into separate rows?
  • How can I store all rows in an array, like $arr = $dbh->query(...)? This does not work because it is still an object
I can of course run under the foreach, and do $arr[] = $row, but that seems a bit silly..
 
Back
Top