2013-10-11 37 views
-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 
} 

回答

2
while($row = $stmt->fetch()){ 
    $rows[] = $row; //use $rows later 
    //Do something here with $row 
} 
+2

刚才看到复制。只需使用$ rows = $ stmt-> fetchAll(); – AbraCadaver