Automatically Deleting Data in MySQL
Sunday July 15, 2007
In a recent forum posting, Dave wrote:
"Hi, I wrote an online prayer page script for my church and all is working well except for the fact of deletions. I need the entries to auto-delete after a given amount of days. So far what I have come up with is
$sth=$dbh->prepare("select *, TODAYS(CURRENT_DATE-TODAYS(stop_date) as expire from prayer_board where stop_date<=DATE_ADD(stop_date, interval 72 hour)");
That is the select statement with stop_date being a column containing a timestamp collected when the user submits the post and what happens is, if you use something like: print"$ref->{'expire'}"; you will get the number of days since the column was created. What I'm needing to do is make the column go away after, say, 30 days or how ever long the post should remain active. I've tried all kinds of things to no avail-I guess you could say I'm getting my mysql education the hard way.
Any help, ideas would be much appreciated."
Can you help Dave? Interested in the responses of other readers? Visit our forum today.
"Hi, I wrote an online prayer page script for my church and all is working well except for the fact of deletions. I need the entries to auto-delete after a given amount of days. So far what I have come up with is
$sth=$dbh->prepare("select *, TODAYS(CURRENT_DATE-TODAYS(stop_date) as expire from prayer_board where stop_date<=DATE_ADD(stop_date, interval 72 hour)");
That is the select statement with stop_date being a column containing a timestamp collected when the user submits the post and what happens is, if you use something like: print"$ref->{'expire'}"; you will get the number of days since the column was created. What I'm needing to do is make the column go away after, say, 30 days or how ever long the post should remain active. I've tried all kinds of things to no avail-I guess you could say I'm getting my mysql education the hard way.
Any help, ideas would be much appreciated."
Can you help Dave? Interested in the responses of other readers? Visit our forum today.


Comments
No comments yet. Leave a Comment