user3728517
user3728517

Reputation: 157

MySQL event using PHP script

I am trying to execute MySQL event using a PHP script. I just try to insert two fields of data in to a table when I execute the PHP script with the event call "joy" in the database but there are no data inserted in the table when I call the event.

My PHP script is:

<?php
include("connect.php");

$insertquery="CREATE EVENT joy
    ON SCHEDULE  AT CURRENT_TIMESTAMP + INTERVAL 3 MINUTE
    DO
      BEGIN
        insert into tri (name,email) values ('swapan','[email protected]');

      END";

 mysql_query($insertquery) or die (mysql_error());
?>

Upvotes: 1

Views: 3601

Answers (2)

worldofjr
worldofjr

Reputation: 3886

You need to use mysqli_query() rather than mysql_query(). This is because your SQL contians more than one query line and mysql_query() doesn't support this.

Additionally, mysql_ functions are deprecated, and you should now use mysqli_.

See http://php.net/manual/en/book.mysqli.php for info on the mysqli functions, and also take a look at Oracle's article about converting from mysql to mysqli https://wikis.oracle.com/display/mysql/Converting+to+MySQLi

Hope this helps!

Upvotes: 1

user3712320
user3712320

Reputation: 116

You should use mysqli instead of mysql, other than that you can test it through phpmyadmin or mysql command line , and by Using SHOW PROCESSLIST you can check whether it is started. If not, run the command

SET GLOBAL event_scheduler = ON;

Upvotes: 1

Related Questions