Need to make a trigger on SQL table which triggers a PHP script on insert in a table

拜拜、爱过 提交于 2020-02-23 04:52:13

问题


I want to know if we can create a trigger in MS SQL server which triggers a php script on each insertion of record


回答1:


Not sure why you want it, but try something in the line of:

DELIMITER @@

CREATE TRIGGER SomeTrigger 
AFTER INSERT ON SomeTable 
FOR EACH ROW 
BEGIN
   DECLARE cmd CHAR(255);
   DECLARE result int(10);
   SET cmd=CONCAT('sudo /path/to/php -f file.php');
   SET result = sys_exec(cmd);
END;
@@
DELIMITER ;



回答2:


  1. I feel it break multilevel architecture and bad idea

  2. If it local php script, must be possible use exec

  3. If You don't need synchronous execution, You can in trigger add info to special table, and periodically check it from outside of SQL server. More this don't break architecture.

  4. If it remote PHP, good solution pointed in Can you call a webservice from TSQL code?



来源:https://stackoverflow.com/questions/20513665/need-to-make-a-trigger-on-sql-table-which-triggers-a-php-script-on-insert-in-a-t

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