just want to ask information.
can I update data automatically in MYSQL using codeigniter 4?
for example: if I have a table named table1 and it has fields number(int),dateStart(datetime). For starters, I enter a value into the number field, which is 0. Can I update the data in the number field to 1 if today’s date has passed the date in the dateStart field?
and if can, how to do it, is it in the model? controller? or is there something new I should know?
2
Answers
So, you are storing some value. If at the time of saving
dateTime
has already passed, then you can reject it with a validator.Otherwise, if it was today and you want it to be updated to the other value at midnight, then you are looking for a cron job.
The following snippet should work however it is recommended a cron job as the first answer.