The first launch of PDO.
$dbh = new PDO("mysql:host=$hostname;dbname=animals", $username, $password);
$stmt = $dbh->query("SELECT * FROM animals");
$stmt->setFetchMode(PDO::FETCH_INTO, new animals);
foreach($stmt as $animals)
{
echo $animals->name;
}
If I skip the method setFetchMode(), then I need to call $animals["name"], which I don't want.
But I do not want to call setFetchMode()for every request that I make.
Is there a way to set FetchMode by default? Or some other way to make objects query()return with one global setting.
source
share