Home >Database >Mysql Tutorial >Why Am I Getting a 'You have an error in your SQL syntax' Error When Creating a MySQL Event from PHP?

Why Am I Getting a 'You have an error in your SQL syntax' Error When Creating a MySQL Event from PHP?

Susan Sarandon
Susan SarandonOriginal
2024-11-10 13:30:02678browse

Why Am I Getting a

MySQL Event Creation Error from PHP Script

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:

  1. 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 ;
  2. Turn on the Event Handler:

    SET GLOBAL event_scheduler = ON;  -- turn her on and confirm below
  3. Confirm Activation:

    show variables where variable_name='event_scheduler';
  4. 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn