Trying out PDO for the first time.
$dbh = new PDO(\"mysql:host=$hostname;dbname=animals\", $username, $password);
$stmt = $dbh->query(\"SELECT * FROM ani
Since PDO would need to know what object you want to fetch into, you would need to specify it manually. But of you just want to use the object to retrieve the data rather than an array and do not care if its not an animal object, you can use anonymous objects by default when you set the attribute after the connection string which could be done in a wrapped constructor
$connection = new PDO($connection_string);
//PDO::FETCH_OBJ: returns an anonymous object with property names that correspond to the column names returned in your result set
$connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
Then all queries will return objects. Though it's not exactly what you want its close.
You could also inject the data into your animal class:
while($dataObj = ...) {
$animal = new Animal($dataObj);
}
If you look at the query function it is possible to change some options by passing extra parameters: http://www.php.net/manual/en/pdo.query.php I haven't tested it but it looks like it gets you close to what you want