Hello! I started with mySQL and i want to eliminate my cronjobs, and found about events. I want to create an event every 1 second, and to compare if endtime from table test < SELECT UNIX_TIMESTAMP(), then to set action='no' from the same table test. What i tried CREATE EVENT event ON SCHEDULE EVERY 1 SECOND DO BEGIN SELECT endtime,action FROM test IF(endtime<UNIX_TIMESTAMP(),SET action='no',NULL); END Code (markup): Can you please help me at this query?
First of all you should not use the event as your event identifier, because it is the reserved keyword for th mysql database as you can see "CREATE EVENT" CREATE EVENT evnt ON SCHEDULE EVERY 1 SECOND DO BEGIN SELECT endtime,action FROM test IF(endtime<UNIX_TIMESTAMP(),SET action='no',NULL); END
CREATE EVENT event ON SCHEDULE EVERY 1 SECOND DO BEGIN UPDATE village_buildings SET done=1 WHERE(endtime<UNIX_TIMESTAMP()); DECLARE ppid INT; DECLARE action,build TEXT; DECLARE curl CURSOR FOR SELECT name,town_id,action FROM village_buildings WHERE done=1; OPEN cur1; BEGIN DECLARE EXIT HANDLER FOR NOT FOUND BEGIN END; LOOP FETCH cur1 INTO build,ppid,action; IF action == 'upgrade' THEN UPDATE village_players_villages SET build=build+1 WHERE id=ppid; ELSE UPDATE village_players_villages SET build=build-1 WHERE id=ppid; END IF; END LOOP; END; CLOSE cur1; END Code (markup): I found a way to fix that query but now i got more problems here, i get error at UPDATE village_buildings SET done=1 WHERE(endtime<UNIX_TIMESTAMP()); but if i run it alone it works fine.... can you help me fix this code? I know that if i'll run it at 1 second the website performance will be reduced, but i need to do this for a live system.