How to automatically delete a record from the database after 10 minutes?

Hello. Faced with the problem. I'm doing a website for booking hotel rooms. Theoretically, the script should work like this:
  1. The person comes to the website
  2. The script checks the availability and dates, and shows them to
  3. People choose booking date and room and presses to pay
  4. The script checks for free these rooms
  5. If the rooms are still empty, script writes to database entry with the date of the reservation number, customer data, etc.
  6. The person goes to the payment page of the booking (on Yandex cash, for example)

Now 3 scenario
  1. The man paid for the room and it swung back to the site congratulations on booking
  2. The man closed the page of payment (not paid)
  3. People idle for 10 minutes (not paid)

I probably need to clarify the 5th paragraph. This is done to ensure that no one else was able to book on these dates the room until our man pays it.

Well, the problem is how to delete a record from the database, if the person is not paid for your booking?
cron is not an option. If you set the script execution every 10 minutes, it is likely that people will reserve rooms on the 8th or 9th minute. That is, until the person is paid, the records from the database was removed, which is not good.

I imagine it this way: on the 5th item in the database is written to another string, such as: paid? Yes/no. And after the 5th paragraph, 10 minutes should trigger a script that will check the record in the database for the presence in the column "paid", "no", and deletes the entire row if they are.

How is this implemented? Prompt where to dig?
July 2nd 19 at 14:18
2 answers
July 2nd 19 at 14:20
Option 1 - set the time of booking, start crowns per minute, to remove all unconfirmed reservation over 10 minutes.
Option 2 - start cheduler MySQL and, together with the reservation to create the event of disposal in the absence of confirmation.
Me when the issue has already came up with the 1st option. You confirmed it. Thank you. - Prudence_Hartmann60 commented on July 2nd 19 at 14:23
July 2nd 19 at 14:22
Note when recording in the database the end time of the reservation.
In your business logic to consider all of the expired records were invalid.

Clear expired you can at least once an hour, once a day, at least once a month - it will not matter.
Not. Wait. You are confusing the word "reservation". And the cleaning is very important. You can, for example, to reserve a room for 2 months without paying, then nobody will be able to book my room - Prudence_Hartmann60 commented on July 2nd 19 at 14:25
In principle it is also possible, just the condition "room available" thickens up "a room is available or booked more than 10 minutes without asking". - Prudence_Hartmann60 commented on July 2nd 19 at 14:28
: what's the problem to do the test in the derivation? If booking more than 10 minutes and no confirmation is to be free - Kenyatta commented on July 2nd 19 at 14:31

Find more questions by tags PHPDatabases