我想从每行中选择三件事,然后更新每一行。 代码每分钟运行一次cronjobs。 但是,在可接受的时间范围内更新所有行需要很长时间。 这就是它现在的样子:
$update_query = "UPDATE game_1 SET amount=? WHERE name=?";
$count_query = "SELECT COUNT(*) FROM game_1";
$stmt = $conn->prepare($count_query);
$stmt->execute();
$stmt->bind_result($count);
$stmt->fetch();
$stmt->close();
echo $count . "\n";
$select_query = "SELECT name, speed, amount FROM game_1 LIMIT ?,1";
echo $select_query . "\n";
while($count != 0)
{
$stmt = $conn->prepare($select_query);
$counted = $count-1;
$stmt->bind_param("i", $counted);
$stmt->execute();
$stmt->bind_result($name, $speed, $amount);
$stmt->fetch();
$stmt->close();
$stmt = $conn->prepare($update_query);
$newamount = $amount+$speed;
$stmt->bind_param("is", $newamount, $name);
$stmt->execute();
$stmt->close();
echo "Updated row " . $count . "\n";
$count--;
}
exit;
是否有更好的表现?
无脚本