Invoking a PHP script from a MySQL trigger
The trigger is executed on the MySQL server, not on the PHP one (even if those are both on the same machine).
So, I would say this is not quite possible -- at least not simply.
Still, considering this entry from the MySQL FAQ on Triggers :
23.5.11: Can triggers call an external application through a UDF?
Yes. For example, a trigger could
invoke thesys_exec()
UDF available here:
https://github.com/mysqludf/lib_mysqludf_sys#readme
So, there might be a way via an UDF function that would launch the php executable/script. Not that easy, but seems possible. ;-)
Trouble calling a php script from mysql trigger
You should use something like select
(This is why you get the syntax error.)
And you should use some executable what will run that PHP file. (EG PHP.EXE)
Try something like:
DECLARE result INT;
SET result = (select sys_exec('C:/path/to/PHP.EXE C:/xampp/htdocs/mysite/hello.php'));
MYSQL trigger that externally launches a PHP script
Confirm you're using the right plugin folder:
SHOW VARIABLES LIKE 'plugin_dir';
Recreate the function:
DROP FUNCTION IF EXISTS sys_exec;
CREATE FUNCTION sys_exec RETURNS int SONAME 'lib_mysqludf_sys.so';
Ensure you're using the full path to your executable:
SET RESULT = sys_exec('/usr/bin/php5 /var/www/html/getFriends.php');
And make sure that whatever user MySQL is running as has the permissions to access this script, and do whatever it's doing.
Is there any way I can execute a PHP script from MySQL?
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
Can triggers call PHP Scripts?
Yes, you can call php scripts if you install mysql_udf_sys
Related Topics
How to Zip a Whole Folder Using PHP
How to Log Errors and Warnings into a File
What's Wrong With Using $_Request[]
How to Replace Certain Parts of My String
How to Convert Date to Timestamp in PHP
How to Send 100,000 Emails Weekly
How to Replace "If" Statement With a Ternary Operator ( : )
What in Layman'S Terms Is a Recursive Function Using PHP
How to Explain Composer'S Error Log
How to Update Code That Uses the Deprecated Each() Function
When Should I Use Prepared Statements
Search Form With One or More (Multiple) Parameters
Simplest Way to Profile a PHP Script
Creating the Singleton Design Pattern in PHP5