Original Error:
When attempting to create a MySQL event using a PHP script, an error occurred:
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
Solution:
The error message indicates that the syntax used to create the event is incorrect. The correct syntax for creating an event is:
CREATE EVENT event_name ON SCHEDULE [EVERY | AT] schedule [ON COMPLETION [PRESERVE | NOT PRESERVE]] DO statement(s);
In the original error, the "DELIMITER" statement was incorrectly used. The correct syntax would be:
CREATE EVENT myevent21222 ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 5 MINUTE DO BEGIN UPDATE `team` SET `reg` = '0' WHERE `id` = '1'; END
Alternative for Changing Database Data After 5 Minutes:
If using an event to change database data is not an option, there are other ways to achieve this functionality:
Event Handler Activation:
To ensure that events are executed, the event handler must be turned on using the following statement:
SET GLOBAL event_scheduler = ON;
You can confirm that the event handler is enabled by checking the value of the 'event_scheduler' variable:
SHOW VARIABLES WHERE VARIABLE_NAME='event_scheduler';
Additional Notes:
The above is the detailed content of Why Is My MySQL Event Creation Failing with 'You have an error in your SQL syntax'?. For more information, please follow other related articles on the PHP Chinese website!