Creating event in Mysql

1

I would like to create an event based on 2 situations.

I have a table and column a situation_id with values

  

[1 - free], [2 - busy], [3 - Not available];

And another modified column - it generates the date of modification of the registry.

The event should occur as follows.

Run the event all day at 5 o'clock in the morning.

If the situation_id is = 2 - get the value of the change (date) > 3 days. UPDATE TABLE situacao_id return to value 1.

But I do not know how to create the event this way.

And create the event that if the registration date is > 6 months give a DELETE in the table.

I do not know how to start the commands to create the events in mysql.

Solution: From Mysql 5.1 there are events that we can perform actions in MYSQL.

We make a change in the status of the user's registry. A registration after 3 days from the modification date, returns the available situation.

By the PHPmyAdmin dashboard clicking on the tab bank we have EVENTS.

By clicking on it we can create events that can be by minutes, hours, days, weeks.

It can be run only once as "One Time" or recurring, running as Execute every, informing as day or week or months, etc.

In the settings we entered the execution in mysql Which in my case would be like this:

UPDATE cadastros SET situacao_id = '1' WHERE DATEDIFF(CURDATE(), modified) > 3;

Running, all day at 5 o'clock in the morning checks all entries, if the modification date is more than 3 days it updates the situation to 1 Free.

    
asked by anonymous 16.06.2017 / 15:35

1 answer

0
CREATE EVENT 
    evt_change_status ON SCHEDULE EVERY 24 HOUR 
    STARTS '2017-11-15 05:00:00' DO 
        UPDATE cadastros SET situacao_id = '1' WHERE DATEDIFF(CURDATE(), modified) > 3;
    
14.11.2017 / 18:38