我对 mysql/php 倒带比较陌生。我正在执行一个查询,在我标记当前数据集并重新启动它之后,我需要运行相同的数据集来运行需要很长时间的 shell 脚本。我将在几分钟内运行与 cron 相同的脚本,因此我可以标记另一组并知道我正在获取不同的数据集来运行慢速 shell 脚本。出于某种原因,倒带不起作用,所以它没有使用数据集两次:
if(!($stmt = $mysqli->prepare("SELECT node, model FROM Table WHERE vendor = 'Calix' AND model in ('C7','E7') AND ((update_status NOT in ('u') OR (update_time IS NULL) OR ((DATEDIFF(NOW(),SW_ver_update_time)>14)) )) LIMIT 100"))) //AND ping_reply IS NULL AND software_version IS NULL
{
echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if(!$stmt->bind_result($ip, $model))
{
echo "Binding results failed: (" . $stmt->errno . ") " . $stmt->error;
}
if(!$stmt->execute())
{
$tempErr = "Error select node, model c7,e7 status: " . $stmt->error;
printf($tempErr . "\n"); //show mysql execute error if exists
$err->logThis($tempErr);
}
$stmt1 = $mysqli1->prepare("UPDATE Table SET update_status = 'u' , update_time = UTC_TIMESTAMP() WHERE node = ?");
while($stmt->fetch()) {
print "current ip: " . $ip . "\n";
$stmt1->bind_param("s", $ip);
$stmt1->execute(); //write time stamp and 'u' on ones 'in process of Updating'
}
//rewind db pointer
mysql_data_seek($stmt, 0);
//Circulate through 100 dslams fetched that we marked as in process.
//This takes a long time to execuate and will be running this script concurrently in 5 minutes
//so we need to know what we're working on so we don't fetch them again.
while($stmt->fetch()) {
print "hello current ip: " . $ip . "\n";
//will execute shell script here
//I never see hello print statement
}
我查看了mysql_data_seek,但没有看到使用 fetch() 的示例。倒带后我可以不使用 fetch() 吗?这里有什么问题?谢谢!
*更新:我试过了
$stmt->data_seek(0);
但它仍然不允许我重新使用该查询。如果有人对如何让倒带工作或绕过它有建议,比如存储查询结果,以便我可以在以后重新使用它们而无需重新运行查询,那也没关系。