0

I have no idea to create an event in MYSQL database.

I want to create an event that updates a field from 1 to 0. By default value of a field is 0 in the database but after executing some query I set it back to 1 according to the requirement. The problem is I want to set 1 to 0 on 1st of every month. How can I do this through an event?

I will be thankful if you suggest me the solution as I am new in the field of MYSQL database and PHP.

Fariya
  • 1
  • 1

1 Answers1

1

You can create mysql event using simple sql code

    DELIMITER $$
    CREATE EVENT eventname
    ON SCHEDULE EVERY '1' MONTH
    STARTS '2018-02-01 00:00:00'
    DO 
    BEGIN
     -- your logic and code
    END$$

DELIMITER ;

Event will start working on '2018-02-01' at '00:00:00' (datetime must be in a future date time).

Do not forget enable global event scheduling thread -

SET GLOBAL event_scheduler = 1;