create mysql event on button click, to delete the

2019-07-26 18:25发布

Here is my php page which is called on button click.

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="parth"; // Database name



$con = mysql_connect("localhost","root","") or die('Could not connect to MySQL server: ' . mysql_error());
//echo"Connected to MySQL server";
mysql_select_db("parth") or die('Could not connect to database' . mysql_error());
//echo "Connected to Database";



$sql="CREATE EVENT gold ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 3 SECOND
DO
DELETE FROM table LIMIT 1;";
mysql_query($sql);
echo "done";
?>

the echo message "done" is displayed

But the event query does not get executed. I have given the privileges too. Just used 3 SECOND for development purpose.

1条回答
神经病院院长
2楼-- · 2019-07-26 18:57

Try this:

<?php
error_reporting(E_All);
$sHost = "localhost";
$sUsername = "root";
$sPassword = "";
$sDb = "parth";

$con = mysql_connect($sHost, $sUsername, $sPassword) or die('Could not connect to MySQL server: ' . mysql_error());
echo"Connected to MySQL server";

mysql_select_db($sDb) or die('Could not connect to database' . mysql_error());
echo "Connected to Database";

$sResult = mysql_query("CREATE EVENT gold ON SCHEDULE EVERY 3 MINUTE STARTS CURRENT_TIMESTAMP + INTERVAL 3 SECOND DO DELETE FROM table LIMIT 1;") or die(mysql_error());
echo "Done";
查看更多
登录 后发表回答