I am playing around with MySql Events for the first time. Here is the event...
DELIMITER $$
CREATE EVENT testEvent
ON SCHEDULE EVERY 1 minute STARTS '2014-01-01 03:00:00'
DO BEGIN
/*
INSERT INTO test(text) VALUES ('text');* <- THIS WORKS JUST FINE
*/
SET @exec_var = sys_exec('c:\wamp\bin\php\php5.4.12\php c:\mySite\testit.php');
END $$
DELIMITER;
The sys_exec()
call to php doesn't seem to work and I can't figure out why. There isn't much on the internet about this. I know the php script works because when I run c:\wamp\bin\php\php5.4.12\php c:\mySite\testit.php
at the command line I get results. testit.php just does the same exact insert that is commented out in the event. Any ideas why sys_exec()
isn't running my script? Or if there are errors how would I go about logging or viewing them?
(I know there are probably security concerns and other things I haven't thought of yet. This is just initial proof of concept stuff. But if you see any reason why I shouldn't go down this path and use a PHP daemon instead I'd be interested in reasons why. This way just seems like it'd be much simpler to get up and running than learning/setting up a PHP daemon.)
Thanks!
This is all that is in the testit.php
script...
try
{
$dbh = new PDO("mysql:host=********;dbname=********", ********, ********);
$dbh->setAttribute( PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true );
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
}
catch(PDOException $e) { echo $e->getMessage(); }
$q1 = $dbh->prepare("INSERT INTO test(text) VALUES ('text')");
$q1->execute();