1

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());
?>
1
  • 2
    You can't do that with the deprecated mysql_* functions. These are more than one statement, so you've got to use mysqli or PDO with multiquery statements, if you want to do this with PHP. Commented Aug 25, 2014 at 16:20

2 Answers 2

1

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;

Sign up to request clarification or add additional context in comments.

1 Comment

i am do this before event is enable on server any other suggestion?
1

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.