软删除和恢复(MySQL、PHP)
我需要能够删除消息并恢复它们,直到页面不重新加载。所以我的“消息”表中有一个字段“is_deleted”。我想要的是删除之后的这些“已删除”记录。对此最好的解决方案是什么?
I need to be able to delete messages and to restore them until the page is not reloaded. So I have a field 'is_deleted' in my 'messages' table. What I want is to delete these 'deleted' records after it. What would be the best solution for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于您的需求,“清除”按钮可能是您想要的,或者很多时候人们会使用 cron job 并将
is_deleted
设置为 NullableDATETIME
字段,如果 x 天后,它仍然显示为被删除,则会自动从数据库中删除。因此,如果自动方式对您有吸引力并且您在 Linux 上,请查看 Cron 作业;如果在 Windows 任务计划程序上,请查看 Cron 作业。如果您想要 cron 的示例,我需要知道您希望从系统中清除记录的频率,我将为您提供一个示例。
例如,要每 5 分钟运行一次删除脚本:
您仍然需要编写 purgeDeleted.php 脚本,但这是通过 Linux 中的 cron 作业运行 php cli 脚本的设置。
It depends on your needs, a "purge" button may be what you want or a lot of times people will use a cron job and set the
is_deleted
to be a NullableDATETIME
field, if after x days, it still shows as being deleted, it is automatically deleted from the database.So if the automatic way appeals to you and you are on linux look at Cron jobs or if on windows Task Scheduler. If you would like an example of the cron, I need to know how frequently you would want the records purged from the system and I will provide you with an example of one.
For example, to run the delete script every 5 minutes:
You will still have to write the purgeDeleted.php script, but that is the setup for running a php cli script via a cron job in Linux.