Is there any way I can execute a PHP script from MySQL?

匿名 (未验证) 提交于 2019-12-03 01:05:01

问题:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!