I'm trying to create a while loop from the returned execution of a PDO statement in a class call Posts, but it's creating an infinite while loop even though the number of rows returns correct. This seems simple...Am I writing this wrong?
public function getRecent()
{
$sql = "SELECT * FROM posts ORDER BY createdate DESC LIMIT 5";
$stmt = $this->db->prepare($sql);
$stmt->execute();
return $stmt;
}
$post = NEW Posts($db);
echo $post->getRecent()->rowCount(); //5 results(correct)
while ($row = $post->getRecent()->fetch())
{
//Creates infinite loop
}