-1
我需要幾次遍歷查詢的結果。在第一次循環之後,由於指針位於底部,我無法再通過結果。我怎樣才能讓它回到頂端?我不想再次運行查詢,因爲這只是要用盡更多的資源並返回相同的結果。重置mySQL結果(PDO)的行指針
$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
}
剛纔看到複製。只需使用$ rows = $ stmt-> fetchAll(); – AbraCadaver