Remove Mysql row after specified time

前端 未结 5 1734
忘了有多久
忘了有多久 2020-12-21 06:46

I\'m trying to create a computer reservation system, where user chooses a computer and select the time how long he will be using this PC. In that time other persons can\'t r

5条回答
  •  猫巷女王i
    2020-12-21 07:00

    To be complete in the solution, you need to run a CRON job which calls a query to remove all reservations that have a reservation_time + (15 * 60) < unix_timestamp().

    I am assuming you have a time that the reservation was placed or started and are using UNIX/Epoch Timestamps.

    Instead of doing a expires_now, if you know it will always be a fixed interval ie 15 minutes, you can do:

    DELETE FROM reservations WHERE  reservation_time + (15 * 60) < unix_timestamp() 
    

    Something you could look into is managing cron job's from PHP, http://www.highonphp.com/cron-job-manager.

    The above script will, when a reservation is created, insert an entry into /etc/cron.d/ and you could configure it to run at the expected reservation endtime. Then inside the php file which would be executed, you could do:

    DELETE FROM reservations WHERE id = :id
    

提交回复
热议问题