Reputation: 13061
i'm trying to update some big table in this way:
<?php
$tables = array("table1","table2","table3","table4","table5");
foreach ($tables as $table) {
$res = mysql_query("SELECT * FROM {$table}");
while($row = mysql_fetch_array($res)){
$data = $row['data'];
$data = gmdate('Y-m-d H:i:s', strtotime($data));
mysql_query("UPDATE {$table} SET data='$data' WHERE user_id='".$row['user_id']."'";);
}
}
?>
Every tables have about 80.000 rows and process will take too much time to finish. How can i solve this using an equivalent function of gmdate
in mysql? Thanks! :)
Upvotes: 0
Views: 2976
Reputation: 3118
you can use mysql's STR_TO_DATE function to update, use this function in update query. try this
SELECT STR_TO_DATE("Fri, 23 Nov 2012 10:00:27 +0000", "%a, %d %b %Y %H:%i:%s +0000");
use output ot STR_TO_DATE and put it in the format you needed.
you can use following single update query
mysql_query('UPDATE {$table} SET data= STR_TO_DATE(YOURDATACOLUMN, "%a, %d %b %Y %H:%i:%s +0000"); WHERE user_id="'.$row['user_id'].'"';);
Upvotes: 4
Reputation: 491
Use select DATE_FORMAT(CURRENT_DATE(),'%Y-%m-%d')
to show the current date in Y-m-d format.
Upvotes: 0