Home >Database >Mysql Tutorial >How to Fix 'Incorrect Delimiter' Error When Creating MySQL Events with PHP?

How to Fix 'Incorrect Delimiter' Error When Creating MySQL Events with PHP?

Barbara Streisand
Barbara StreisandOriginal
2024-11-09 16:19:02381browse

How to Fix

MySql Event Error using PHP

Problem:

mysql_query() returns an "incorrect delimiter" error when creating an event in MySQL 5.5. Can anyone help resolve this issue?

Alternative Methods:

If creating an event is not feasible, are there alternative ways to change data in the database after a specified time interval?

Solution:

Creating the Event:

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 ;

Turning on the Event Handler:

SET GLOBAL event_scheduler = ON;  -- turn her on and confirm below

Confirming Event Handler Status:

show variables where variable_name='event_scheduler';

Checking Event Info:

show events from so_gibberish2; -- note so_gibberish2 is my database name

Disable/Enable Event:

ALTER EVENT myevent21222 disable;
ALTER EVENT myevent21222 enable;

Alternative Methods for Time-Based Data Changes:

If creating an event is not possible, consider using a scheduling service like cron or Windows Task Scheduler. These services can execute a script at a specified time interval, which can then perform the necessary database updates.

The above is the detailed content of How to Fix 'Incorrect Delimiter' Error When Creating MySQL Events with 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