I am writing my own simply ORM using PDO. My question is if you can force PDOStatement::fetchAll() method to return array of objects of stdClass? For example:>
This will do it:
prepare("SELECT name, colour FROM fruit");
$sth->execute();
$result = $q->fetchAll(PDO::FETCH_OBJ);
//$result contains an array of stdObjects
?>
However even cooler way is to get PDO to instantiate your own class and populate the properties for you:
Example #4 Instantiating a class for each result
The following example demonstrates the behaviour of the PDO::FETCH_CLASS fetch style.
prepare("SELECT name, colour FROM fruit");
$sth->execute();
$result = $sth->fetchAll(PDO::FETCH_CLASS, "fruit");
//$result contains an array of fruit objects
?>
Source: http://www.php.net/manual/en/pdostatement.fetchall.php