Issue:
When attempting to create a MySQL event using a PHP script, users encounter the 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
Solution:
To resolve this issue, follow these steps:
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 Activation:
show variables where variable_name='event_scheduler';
Check Event Info (if Needed):
show events from so_gibberish2; -- note so_gibberish2 is my database name -- obviously use your database name above
Alternative for Data Modification After a Time Delay:
If the event-based approach is problematic, consider using a PHP Job Queue or Cron Job to perform the data modification at a scheduled interval.
The above is the detailed content of Why Am I Getting a 'You have an error in your SQL syntax' Error When Creating a MySQL Event from PHP?. For more information, please follow other related articles on the PHP Chinese website!