开发者

How do I automatically Delete Rows from MySQL Database on specific date?

I know there has to be a way to automatically delete a row in a MySQL table on a specified date. I am just brain dead today : /

Let's just say I have CMS that I input posts and want one of the fields in the table to be "delete_date" and if I put a date in that field it would delete that row on the date specified. If I do not enter a date it would not auto delete.

What would be the best way to d开发者_如何转开发o this using PHP/MySQL. Tips or examples would help.


Run a scheduled task (cron job) which deletes all the rows where the delete_date field is greater than or equal to the current date.


A basic query:

DELETE * FROM cms_table WHERE delete_date='$the_date_to_delete'

( see: http://dev.mysql.com/doc/refman/5.0/en/delete.html )


I don't know PHP, but this is really a language agnostic question unless you don't know how to execute SQL in the language.

You can run a scheduled task, as @tylerl suggests. Easy to do in a .Net language, not sure about PHP. You also have the option of running a service if you want old records to be continually deleted throughout the day. Again, easy enough in .Net.

If, however, you have an application (PHP, .Net, etc) that you want to physically check for records to delete:

delete * from myTable where recordDateField > 'cutOffDate' // I think you pass parameters with a `$` - not sure
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜