Jump to content

Archived

This topic is now archived and is closed to further replies.

vigiw

Table Truncating/Emptying Script

Recommended Posts

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_forecast

Thanks in advance. ;D

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
I can't think of a more dangerous script to run... why do you need to do this?

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites
I'd feel better if it was a DELETE with a WHERE clause date restriction ;-)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.