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?

5
  • How does the error message end? Commented Jun 18, 2016 at 20:58
  • 1
    Don't add the delimiter part to your code. phpMyadmin does that for you automatically Commented Jun 18, 2016 at 21:02
  • Oh, now it should work, I think. But I get the following message: "Errormessage: This command is not supported in the prepared statement protocol yet". Well, I'll try it using mysqli_query ... Commented Jun 18, 2016 at 21:06
  • Works perfectly, thank you! Commented Jun 18, 2016 at 21:13
  • You have 3 questions, none have accepted check marks, and no upvotes on those that help you? Commented Aug 4, 2016 at 19:34

3 Answers 3

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;
Sign up to request clarification or add additional context in comments.

2 Comments

Already works by deleting the Delimiter part. Nevertheless, thank you very much!
glad you got it working. Don't forget it is still running :p
-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 |

Comments

-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

6 Comments

i have not seen DELIMITER | before in the question, and it works then
But not in phpMyAdmin
and OP has change his question
Actually not, he only added the rest of the error message
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.