可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.
回答1:
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
回答2:
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 ;
source
回答3:
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.