我需要循环查询几次结果。在第一个循环之后,由于指针位于底部,我无法再次查看结果。我怎样才能让它回到顶端?我不想再次运行查询,因为这只会耗尽更多资源并返回相同的结果。
$stmt = $conn->prepare("SELECT * FROM customers");
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();
//This kind of loop will repeat elsewhere in the code
while($row = $stmt->fetch()){
//Do something here
}
答案 0 :(得分:2)
while($row = $stmt->fetch()){
$rows[] = $row; //use $rows later
//Do something here with $row
}