问题
I'm having an issue with my PHP code trying to create events within MySQL. I begin with creating a string like this:
<?php
$sql="DELIMITER $$ CREATE EVENT `$test_name` ON SCHEDULE EVERY $time1 $sched2
STARTS '$start_date $start_time' DO BEGIN ";
$sql .="INSERT INTO blah (foo,bar); ";
$sql .="END$$ DELIMITER ;";
mysql_query($sql,$dbh);
?>
But I keep getting Syntax Errors starting with DELIMITER $$ CREATE EVENT
. Without the semicolon behind (foo,bar);
the event triggers with a unexecuted payload.
Any ideas on where I'm going wrong?
Thanks!
回答1:
After some more research, it turns out to be the mysql interface not playing well with DELIMITER. Switching to mysqli worked.
For some reason the global scheduler stopped running as well without me noticing so once I checked for it with "show processlist" and restarted it, now my jobs are firing. So I think it will run without the DELIMITER noise.
来源:https://stackoverflow.com/questions/10923300/mysql-event-scheduler-delimiter-using-php