【发布时间】:2020-05-06 00:49:30
【问题描述】:
我正在尝试从类调用 Posts 中返回的 PDO 语句的执行创建一个 while 循环,但它正在创建一个无限的 while 循环,即使 行数返回正确。这看起来很简单……我写错了吗?
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
}
【问题讨论】: