我试图在网页中一次又一次地访问数据。有没有更好的办法 ?movetofirst()、movetolast()、movetoprevious()、movetonext() 之类的东西可能会很好。
现在我正在将结果集作为数组检索(使用 fetchall())并一次又一次地重新使用该数组。
有没有像下面这样的事情?我不需要一次又一次地执行查询。如果结果/数组有数百行,则将数据保存在数组中并消耗资源。
$sql = 'SELECT cityname, statename FROM TBLPLACES ORDER BY cityname, statename';
$stmt = $conn->query($sql);
if ($stmt) {
while($row=$stmt->fetch()){
// do some thing
}
// do some more thing
//
// now here, can i access same $stmt object
// to fetch resultset again without executing
// $stmt = $conn->query($sql); again ?
// (no change in query sql, need to fetch the same static data again.)
//
// something like below will be nice.
//
// $stmt->movetofirst();
// while($row=$stmt->fetch()){
// do some thing;
// }
}