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

后端 未结 3 710
轻奢々
轻奢々 2020-12-10 01:39

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 p         


        
相关标签:
3条回答
  • 2020-12-10 02:08
    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

    0 讨论(0)
  • 2020-12-10 02:21

    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

    0 讨论(0)
  • 2020-12-10 02:25

    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.

    0 讨论(0)
提交回复
热议问题