Home > Database > Mysql Tutorial > body text

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

Susan Sarandon
Release: 2024-11-10 13:30:02
Original
634 people have browsed it

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
Copy after login

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

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

    show variables where variable_name='event_scheduler';
    Copy after login
  4. Check Event Info (if Needed):

    show events from so_gibberish2; -- note so_gibberish2 is my database name
    -- obviously use your database name above
    Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template