开发者

Alternative to fetchall (PDO)?

开发者 https://www.devze.com 2023-03-17 05:56 出处:网络
What is alternative to fetchall for real time loop? Consider this: $query = $db->prepare(\"SELECT * FROM record WHERE status = 0\");

What is alternative to fetchall for real time loop?

Consider this:

$query = $db->prepare("SELECT * FROM record WHERE status = 0");
$query->execute()开发者_Go百科;
$Record = $query->fetchall(PDO::FETCH_ASSOC);

foreach ($Record as $row) {
 echo $row['name'];
 sleep(5)
}

While its looping and echo'ing, I updated status = 1 from the console but it will still show the record which it shouldn't.


How about a simple fetch(): http://us3.php.net/manual/en/pdostatement.fetch.php

$query = $db->prepare("SELECT * FROM record WHERE status = 0");
$query->execute();

while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
 echo $row['name'];
 sleep(5)
}


The results of the query are calculated once, when you run the query. If you need to get all new results with status = 0, you'll need to rerun the query.

0

精彩评论

暂无评论...
验证码 换一张
取 消