开发者

Delet data froma a table after certain time interval. lets say (60 mins)

I want to delete data from a table after a time interval has been passed and fill it with NULL value. I basically want that data to get expired after a certain interval of time. Is there any way to do it us开发者_如何学编程ing Php. database is in Mysql. Thanks.


You're looking for some kind of cronjob to run every minute.

Why do you want to fill in null values? It would be best to have smallint(1) field that you fill with 1 if the row is deleted. That way you'll always be able to retrieve 'deleted' data if necessary.


Use a TIMESTAMP DEFAULT CURRENT_TIMESTAMP field to track how old the record is, and a cron job to delete old records.


You can do this using Event Scheduler.

Query can be something like this:

UPDATE `your_table` SET `your_table_column` = NULL WHERE 1


Why dont you try adding another column which says

expiry_time

(here you add 60 mins to the created date)

And when you are checking for the expiry, check against this column

I dont know about your exact issue, but this might come in handy

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜