Jump to content


Photo

Table Truncating/Emptying Script


  • Please log in to reply
5 replies to this topic

#1 vigiw

vigiw
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts

Posted 20 August 2006 - 09:31 PM

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

#2 vigiw

vigiw
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts

Posted 21 August 2006 - 01:55 AM

*bump*

#3 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 21 August 2006 - 04:26 PM

If by truncate you mean
TRUNCATE tablename

Then you can retrieve the list of tables in the database
SHOW TABLES;

and then iterate through the list, truncating each.
while (list($tablename) = mysql_fetch_array($result))
{
    mysql_query("TRUNCATE tablename");
}


#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 August 2006 - 05:38 PM

I can't think of a more dangerous script to run... why do you need to do this?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 vigiw

vigiw
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts

Posted 21 August 2006 - 09:02 PM

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. :)

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 August 2006 - 11:36 PM

I'd feel better if it was a DELETE with a WHERE clause date restriction ;-)
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users