A
A
Andrey Kurganov2017-04-18 18:02:17
PHP
Andrey Kurganov, 2017-04-18 18:02:17

How to make a value in the database change after a certain time?

The task is that it is necessary to change the data of the MySQL table (id_status ) after a certain time. For example, a client makes a reservation at 14:00. The status of the place is "Booked" (id_status = 1). If during the day he did not pay for the order, then change the value of id_status = 0. How can I implement this using (PHP, MYSQL)?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
T
ThunderCat, 2017-04-18
@kurganov_ai

If during the day he did not pay for the order, then change the value of id_status = 0.

This is the wrong approach in architecture, hence the problems with the wrong statement of the problem. You must have a separate object of the reservation, and a separate table for it, in which it is easy to check how long ago the reservation was made, if more than some time and not paid - it is not taken into account in the selection of occupied objects. Nothing needs to be updated, and if the booking logic changes tomorrow, the main properties of the object will not be affected. Plus there will be statistics on who booked when and how, with a history of bookings and payments.

M
mistergonza, 2017-04-18
@mistergonza

Either cron and a command that checks whether a day has passed since the booking and changes the status.
Or, somewhere in the model, make the isBooked method that will return true if the status is 'booked' and the day has not yet passed, and false otherwise. But most likely it will be necessary to add logic somewhere that will change the status in the database if this method returns false (as in the answer above, you can write this logic into a trigger, they are in mysql).
Without examples, it is difficult to advise something more detailed.

L
Lander, 2017-04-18
@usdglander

cron

M
Max Kostikov, 2017-04-18
@mxms

MySQL has a built-in scheduler or events. You can create a one-time event for each such event with the removal of the necessary one, or make a single event that will do the same for the entire database at certain intervals.

O
OnYourLips, 2017-04-19
@OnYourLips

You need a handler running in the background.
Under certain conditions, it will perform certain actions.
Usually a console application is made that uses the console kernel, but your classes, configs, etc. are the same.
You can run such an application by cron every minute, or you can make it a daemon.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question