1. Home
  2. Computing & Technology
  3. Databases
photo of Mike Chapple
Mike's Databases Blog

By Mike Chapple, About.com Guide to Databases since 2000

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.

Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore Databases
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Databases

©2009 About.com, a part of The New York Times Company.

All rights reserved.