I want to invoke and execute a PHP script from a MySQL procedure. Is this possible?
我想从MySQL过程调用并执行PHP脚本。这可能吗?
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.
[编辑]我实际上是在满足条件时尝试引发事件 - 例如当我的表字段值与当前时间匹配时。然后,我想捕获事件并发送电子邮件。
3 个解决方案
#1
18
It's possible, See the MySQL FAQ for an explanation of how
有可能,请参阅MySQL常见问题解答,了解如何解释
Can triggers call an external application through a UDF?
Can触发器可以通过UDF调用外部应用程序吗?
But it's likely to be bad design on your part if you have to resort to this
但如果你不得不诉诸于此,那么你的设计可能会很糟糕
#2
12
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 ;
资源
#3
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.
为了解决您的问题,您可以为任务创建表。从存储过程中,您可以为此表添加任何字符串以执行任务。在服务器上,您可以通过crontab运行PHP脚本。脚本将检查此表并进行一些操作。
#1
18
It's possible, See the MySQL FAQ for an explanation of how
有可能,请参阅MySQL常见问题解答,了解如何解释
Can triggers call an external application through a UDF?
Can触发器可以通过UDF调用外部应用程序吗?
But it's likely to be bad design on your part if you have to resort to this
但如果你不得不诉诸于此,那么你的设计可能会很糟糕
#2
12
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 ;
资源
#3
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.
为了解决您的问题,您可以为任务创建表。从存储过程中,您可以为此表添加任何字符串以执行任务。在服务器上,您可以通过crontab运行PHP脚本。脚本将检查此表并进行一些操作。