Jump to content

[SOLVED] clearing entrys from your database ?


andrew_biggart

Recommended Posts

Cron Job using PHP CLI (Command Line Interface).

 

Basically the cron job is set to run every x minutes or hours or days etc. (Google Cron Job to read more up on that).

 

What a cron job does (or scheduled task) is automatically run some code at the times specified. An example of a line for a script that runs every day in a cron job would be:

 

0 0 * * * /usr/bin/php -f /home/username/deleteDaily.php

 

Then the code for your script to erase the entries would be something like this:

deleteDaily.php

<?php
// mysql connection info

mysql_query("DELETE FROM table_name WHERE datecol > " . strtotime('+1 week'));
?>

 

This "should" (test it without deleting before using) delete any entry that is > 1 week old. I do not know how MySQL different date fields handle a unix timestamp, so that may or may not work.

 

But that is the basic gist, for a cron job running via PHP CLI check out this Tutorial.

 

For how to do this on a windows server, look into Scheduled tasks.

You can do it via PHP code or through a Cron Job (http://en.wikipedia.org/wiki/Cron), which is a method to automatically run scripts every x period of time.

If you want to use PHP for that you will have to create a function and run it every time you modify your database (add record,update record).

 

Do a google search for deleting mysql records older than.

 

Hope this helps.

 

Angel

Archived

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

×
×
  • Create New...

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.