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.
In order to connect a MySQL database to PHP, you require MySQL on your computer, a tool to create and manage databases, and PHP installed. The most popular ways to connect a PHP script to MySQL are MySQli and PDO.
Instead of having PHP code in db you could have just a class name that has method called, say, execute() . Whenever you need to run your custom PHP code just instantiate the class of name you just fetched from db and run ->execute() on it.
Yes, you can. It depends on which version of PHP you're using, but if you're using PHP5+ you can use Microsoft's SQL Server Driver for PHP. Make sure you use version 2, which gives you the PDO functionality as well as the procedural style.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With