Daguse Posted June 22, 2008 Share Posted June 22, 2008 I am trying to set up a way to auto delete rows in my DB after 3 days if they have not been locked. How would be the best way to do this? Thanks for all the help. Quote Link to comment https://forums.phpfreaks.com/topic/111377-auto-delete-row-after-3days/ Share on other sites More sharing options...
cujo Posted June 22, 2008 Share Posted June 22, 2008 A number of years ago, around 2002 I believe, when I first got into PHP and I had my first webserver, there was a "crontab" file that could be modified and set to execute scripts at pre-determined intervals. I'm not sure if 'crontab' is obsolete now, you might want to do a google search. Alternatively, you can add a 'timestamp' column to your table, and place the code below in a script that you know a user will execute - preferably in the page where you are inserting the values into the table. By the way, the number 259200 is the number of seconds in 3 days. "time" is the name I happened to choose for the timestamp column. $timestamp = date(U); $prevtime = $timestamp - 259200; mysql_query("INSERT INTO table values ('$var1,'$var2',$timestamp)"); mysql_query("DELETE FROM table WHERE time < '$prevtime'"); Quote Link to comment https://forums.phpfreaks.com/topic/111377-auto-delete-row-after-3days/#findComment-571733 Share on other sites More sharing options...
aseaofflames Posted June 22, 2008 Share Posted June 22, 2008 you could use cron jobs (or cron tabs) for this. If you host doesn't support them you can use this website: http://www.webcron.org/index.php?&lang=en web cron allows you to run a script at a certain interval (once every hour to once every year), and it can be password protected. (it works fine with my .htaccess password protected script) Quote Link to comment https://forums.phpfreaks.com/topic/111377-auto-delete-row-after-3days/#findComment-571749 Share on other sites More sharing options...
fenway Posted June 23, 2008 Share Posted June 23, 2008 I am trying to set up a way to auto delete rows in my DB after 3 days if they have not been locked. How would be the best way to do this? Thanks for all the help. v5.1 has an event scheduler... Quote Link to comment https://forums.phpfreaks.com/topic/111377-auto-delete-row-after-3days/#findComment-572412 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.