D
D
DmitrijP2019-12-15 22:30:29
PHP
DmitrijP, 2019-12-15 22:30:29

How to change value in mysql after some time?

Hello :)
I have a function on the site to mark that an item from the mysql database was found, when I click on the button, I change the column with the initial value "unchecked" to "checked", but how can I make this value, let's say a month later, automatically return to "not verified"?
Sorry if the question is simple, but it will help a lot in learning.
Answers are better code, so that it is easier to understand.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
FanatPHP, 2019-12-15
@DmitrijP

Don't do it at all.
The database is not your diary in which you are accustomed to correct two by three with an eraser.
There is no need to correct anything in the database in a month.
You just need to make a column that contains the date of the status change.
And in the status request, just take into account the date. If checked and less than a month has passed, then checked.
Otherwise - not tested.

T
Talyan, 2019-12-15
@flapflapjack

update tablename set tablename.valuename = true where tablename.date_created +  INTERVAL 1 month < NOW()

cron, or any call to any script

R
Roll Back, 2019-12-15
@renaay

Unfortunately, using the PHP language, such a thing can hardly be done without third-party libraries (or crutches), but if you really want to, there is ReactPHP.
Therefore, the most loyal and common solution to this problem looks like this:
- We write a script that runs into the database, takes the date and checks it
- We take any task scheduler, for example cron, we tell him, they say, please run this script once every N hours/months/ days.
As a result, the script will run once every (for example, a day), select all records that were created 30 days ago and will put down the necessary status for them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question