2

I'm trying to initiate a MySQL Event using a PHP script. It works using phpMyAdmin (although I get the same error) but not using the script. I get the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DELIMITER' at line 1

DELIMITER |
CREATE EVENT myevent21222
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 5 MINUTE
DO
  BEGIN
    UPDATE `team` SET `reg` = '0' WHERE `id` = '1';
  END |
  # MySQL lieferte ein leeres Resultat zurück (d.h. null Datensätze).
DELIMITER ;

Can anyone figure out the problem?

Is there any alternative for changing data in a database after 5 minutes after a user had done something?

Drew
  • 24,851
  • 10
  • 43
  • 78
AnUser1
  • 79
  • 8

3 Answers3

3

Create the Event:

drop event if exists `myevent21222`;
DELIMITER |
CREATE EVENT myevent21222
  ON SCHEDULE EVERY 5 MINUTE STARTS '2016-01-01 00:00:00'
  ON COMPLETION PRESERVE
DO
  BEGIN
    UPDATE `team` SET `reg` = '0' WHERE `id` = '1';
  END |
  # MySQL lieferte ein leeres Resultat zurück (d.h. null Datensätze).
DELIMITER ;

Turn on the event handler:

SET GLOBAL event_scheduler = ON;  -- turn her on and confirm below

Confirm it is on:

show variables where variable_name='event_scheduler';

Check out event info:

show events from so_gibberish2; -- note so_gibberish2 is my database name 

-- obviously use your database name above

enter image description here

Look at the manual page for what ON COMPLETION PRESERVE means as well as other things.

Disable or enable it:

ALTER EVENT myevent21222 disable;
ALTER EVENT myevent21222 enable;
Drew
  • 24,851
  • 10
  • 43
  • 78
-1

you must set the *DELIMITER** first:

see for phpmyadmin : Creating functions in phpMyAdmin - Error: access denied you need the super privilege for this operation

DELIMITER |

CREATE EVENT myevent21222
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 5 MINUTE
DO
  BEGIN
    UPDATE `team` SET `reg` = '0' WHERE `id` = '1';
  END |
  # MySQL lieferte ein leeres Resultat zurück (d.h. null Datensätze).
DELIMITER ;

The first Post i have seen

Community
  • 1
  • 1
Bernd Buffen
  • 14,525
  • 2
  • 24
  • 39
-1

Try this.

     DELIMITER |

     CREATE EVENT myevent21222
     ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 5 MINUTE
     DO
        BEGIN
        UPDATE `team` SET `reg` = '0' WHERE `id` = '1';
        END ;
       # MySQL lieferte ein leeres Resultat zurück (d.h. null Datensätze).
     DELIMITER |
Faizan Younus
  • 793
  • 1
  • 8
  • 13