0
default command time schedule

CREATE EVENT event_name
ON SCHEDULE
EVERY {x}
{SECOND | MINUTE | HOUR | DAY | MONTH | YEAR | WEEK}
DO
{SQL COMMAND};

my own event

$auto = "CREATE EVENT event_name
ON SCHEDULE
EVERY 50 second
DO
INSERT into mytable (id, account, date)
          VALUES('$id', '$account','$date'  )";             


  if(mysqli_query($conn, $auto)){ 
                                                 echo '<script>alert("Data success to save !")</script>';
                                                }
                                                else{
                                                echo '<script>alert("Data failed to save !")</script>';
                                                }           
;

the code should be work fine but the query is not added into mysql table

what i miss?

mr.rico
  • 15
  • 7
  • I think you intend to add data to your table, not a query. What you try to do cannot be done. You have PHP variables in your query, and you seem to expect them to update regulary. I can't see how that would work. The best that could happen is that you insert the same data every 50 seconds, unless you replace the event by another with the same name, but then the whole idea of an MySQL event makes no sense. Anyway, to see why it doesn't work you need to check the MySQL error log. https://dba.stackexchange.com/questions/145627/error-log-location – KIKO Software Jul 09 '18 at 09:26
  • so.. it did not make sense if want insert new data every 50 second or a day automaticaly into db? – mr.rico Jul 09 '18 at 09:30
  • No, the time interval doesn't matter. It's the fact that you set up the same insert, with exactly the same data, to be repeated every time. – KIKO Software Jul 09 '18 at 09:37
  • well in my case... my system have new data every day so the user must add into the database. – mr.rico Jul 09 '18 at 09:39
  • before, i must press a action button to add all data – mr.rico Jul 09 '18 at 09:40
  • If you are using Linux you could set up a Cron job to let PHP insert the data. See: https://code.tutsplus.com/tutorials/managing-cron-jobs-with-php--net-19428 (or using something like Plesk or CPanel). – KIKO Software Jul 09 '18 at 09:43
  • i'm using windows :( – mr.rico Jul 09 '18 at 09:44
  • See the answer here: https://stackoverflow.com/questions/9894804/use-php-to-set-cron-jobs-in-windows – KIKO Software Jul 09 '18 at 09:46

1 Answers1

0

You should run SET GLOBAL event_scheduler = ON; in mysql to start Scheduled Event. To stop it please exicute SET GLOBAL event_scheduler = OFF;

Mahesh K S
  • 719
  • 1
  • 7
  • 15