vigiw Posted August 20, 2006 Share Posted August 20, 2006 Hello, I was wondering if I could create a script or some sort of Cron Job to truncate every table of a database daily, at midnight (Eastern Time) each (new) day. Does anyone have a script to do so? The database name is vigilant_forecastThanks in advance. ;D Quote Link to comment https://forums.phpfreaks.com/topic/18134-table-truncatingemptying-script/ Share on other sites More sharing options...
vigiw Posted August 21, 2006 Author Share Posted August 21, 2006 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/18134-table-truncatingemptying-script/#findComment-77832 Share on other sites More sharing options...
shoz Posted August 21, 2006 Share Posted August 21, 2006 If by truncate you mean [code]TRUNCATE tablename[/code]Then you can retrieve the list of tables in the database[code]SHOW TABLES;[/code]and then iterate through the list, truncating each.[code]while (list($tablename) = mysql_fetch_array($result)){ mysql_query("TRUNCATE tablename");}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18134-table-truncatingemptying-script/#findComment-78145 Share on other sites More sharing options...
fenway Posted August 21, 2006 Share Posted August 21, 2006 I can't think of a more dangerous script to run... why do you need to do this? Quote Link to comment https://forums.phpfreaks.com/topic/18134-table-truncatingemptying-script/#findComment-78182 Share on other sites More sharing options...
vigiw Posted August 21, 2006 Author Share Posted August 21, 2006 I am going to have a weather forecast system using PHP and MySQL to submit weather alerts and retrieve them from a database. All is working, I just need to clear out obsolete data day, after day. :) Quote Link to comment https://forums.phpfreaks.com/topic/18134-table-truncatingemptying-script/#findComment-78290 Share on other sites More sharing options...
fenway Posted August 21, 2006 Share Posted August 21, 2006 I'd feel better if it was a DELETE with a WHERE clause date restriction ;-) Quote Link to comment https://forums.phpfreaks.com/topic/18134-table-truncatingemptying-script/#findComment-78338 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.