I'm using a while loop to pull records from mysql. this is to reset a log that was jacked up on accident, so I'm fixing the previous records by pulling the ID and time-stamp from a backup of the DB and updating the production table with those values.
I was hoping to limit memory usage and thought this solution would use much less, as there are 12,545,628 records in this log table. Pull just the ID and time-stamp fields it busts through 1GB of memory pretty quick.
Is this limiting the memory usage to one record at a time, or is it using the same as a straight pull of all ID's and time-stamps and foreaching over those?
(i've setup a database class so the PDO might look weird)
$sql = 'SELECT id, timestamp FROM log_people WHERE 1';
$Test->sqlQuery($sql);
while ($testdb = $Test->sth->fetch(PDO::FETCH_ASSOC)) {
$Prod->beginTransaction();
try {
$sql2 = 'UPDATE log_people SET timestamp = "'.$testdb['timestamp'].'" WHERE id = '.$testdb['id'];
$Prod->sqlQuery($sql2);
} catch (exception $err) {
$Prod->rollback();
echo $err->getMessage();
}
}
Should I be doing the code below to just pull and modify one record at a time?
while ($count < 12545628){
$sql = 'SELECT id, timestamp FROM log_people WHERE id ='.$count;
$Test->sqlQuery($sql);
$testdb = $Test->sth->fetch(PDO::FETCH_ASSOC)
$Prod->beginTransaction();
try {
$sql2 = 'UPDATE log_people SET timestamp = "'.$testdb['timestamp'].'" WHERE id = '.$testdb['id'];
$Prod->sqlQuery($sql2);
$count++;
} catch (exception $err) {
$Prod->rollback();
//return $err->getMessage();
echo $err->getMessage();
}
}
selectall records? If all records should be updated - why select them?