Reputation: 6269
I want to invoke and execute a PHP script from a MySQL procedure. Is this possible?
CREATE PROCEDURE simpleproc (OUT param1 INT)
BEGIN
Call my php script here
END//
[EDIT]
I am in fact trying to raise an event when a condition is met — for instance when my table field value matches the current time. Then, I want to capture the event and send an email.
Upvotes: 20
Views: 17415
Reputation: 11845
DELIMITER @@
CREATE TRIGGER Test_Trigger
AFTER INSERT ON MyTable
FOR EACH ROW
BEGIN
DECLARE cmd CHAR(255);
DECLARE result int(10);
SET cmd=CONCAT('/usr/bin/php ', '/home/test/beta/demo.php');
SET result = sys_exec(cmd);
END;
@@
DELIMITER ;
Upvotes: 12
Reputation: 2719
For solve your problem you can create table for tasks. From stored procedure you can put to this table any string for task. On server you can run PHP script by crontab. Script will check this table and make some operation.
Upvotes: 3
Reputation: 212522
It's possible, See the MySQL FAQ for an explanation of how
Can triggers call an external application through a UDF?
But it's likely to be bad design on your part if you have to resort to this
Upvotes: 20