I'm relatively new to mysql/php rewind. I am execuring a query, and after I mark the current data set and re-wind it, I need to run the same set to run shell scripts that take a really long time. I'm going to run the same script as a cron in a few minutes, so I can mark another set and know I'm fetching a different data set to run the slow shell scripts on. For some reason, the rewind isn't working, so it's not using the data set twice:
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
}
I looked at mysql_data_seek but I don't see an example that uses fetch(). Can I not use fetch() after a rewind? What's the issue here? Thanks!
*Update: I tried
$stmt->data_seek(0);
But it's still not letting me re-use that query. If anyone has a suggestion of how to get rewind to work, or a way to get around it, like storing the query results so I can re-use them without re-running the query later, that's ok too.