Which keeps giving me Call to undefined method PDO::fetchAll()
This should have given you the hint, that you are using the wrong object. It's PDOStatement::fetchAll as you can see in your second example, or if you want to use it in a while loop PDOStatement::fetch:
while ($row = $result->fetch(PDO::FETCH_ASSOC))
{
$title = $row['title'];
$body = $row['body'];
}
Additional notes:
$result
is a misleading variable name as you might see from the $result->execute()
line. You don't execute a result, you execute a statement. This is why in the manual $stmt
or $sth
(statement handle i guess) are used.
- The
echo
lines should be inside the while loop, otherwise you overwrite again and again, then output only the last row.