有一种方法从一个特定的时间从插入时间计数从mysql删除一行 [英] Is there a way to delete a row from mysql after a certain amount of time counting from insert time

查看:105
本文介绍了有一种方法从一个特定的时间从插入时间计数从mysql删除一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在创建时间后24小时后删除该行。有没有办法在PHP / MySQL中这样做?

I have a requirement to delete a row after 24 hours from its creation time. Is there a way in PHP/MySQL to do this?

时间必须从行的插入时间算起,24小时后必须删除。虽然我们可以写 cron 来检查每一分钟,当没有多少行添加 cron 将运行没有使用。有没有其他机制来做呢?

The time must count from the insertion time of the row and after 24 hours it must be deleted. Although we can write cron to check for every minute, when there are not many rows added cron will run without use. Is there some other mechanism to do it?

推荐答案

如果你有你的mySQL版本> = 5.1.6,

If you have your mySQL version >= 5.1.6 , there is a good feature intended for use in such cases - mySQL events.

这里是一个使用示例 - http://phpmaster.com/working-with-mysql-events/

Here is an example of usage - http://phpmaster.com/working-with-mysql-events/

这篇关于有一种方法从一个特定的时间从插入时间计数从mysql删除一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆