【发布时间】:2011-09-26 09:12:12
【问题描述】:
刚接触 oop,只是想知道为什么这会导致无限循环:
while ($row=$dbh->query("SELECT * FROM animal")->fetch(PDO::FETCH_ASSOC)){
printf("A(n) %s is a type of %s<br />", $row['name'], $row['species']);
}
但是这不会导致无限循环
$sth=$dbh->query("SELECT * FROM animal");
while ($row=$sth->fetch(PDO::FETCH_ASSOC)){
printf("A(n) %s is a type of %s<br />", $row['name'], $row['species']);
}
【问题讨论】:
-
因为首先您每次都在查询数据库。如果有行,那么它将始终为“true”。
标签: php mysql pdo prepared-statement