How to delete mysql row after time passes?

后端 未结 6 796
闹比i
闹比i 2020-11-29 01:56

I have no idea where to start with this one:

I have a database that stores postID and Date.

What I want to do is have my website au

6条回答
  •  悲哀的现实
    2020-11-29 02:15

    Why using cronjobs everyday?? Why not filter data on output. For example in your select check if post date equals today with adding a simple where:

    SELECT * FROM `posts`
    WHERE (DATE(`post_date`) = DATE(NOW()));
    

    This way you're not required to do your database managements/cronjobs on any special time and it will be used just for database managements. Afterwards you can delete unnecessary data at any time using by mysql command like:

    DELETE FROM `posts` WHERE (
        DATE(`post_date`) < DATE(NOW())
    )
    

提交回复
热议问题