0

I have the next mysql trigger:

DELIMITER @@

CREATE TRIGGER Test_Insert
BEFORE INSERT ON sat_clientLocation
FOR EACH ROW 
BEGIN
DECLARE cmd CHAR(255);
DECLARE result int(10);
SET cmd=CONCAT('/usr/bin/php ', '/var/www/html/poi/insertTest.php' , NEW.idLocation);
SET result = sys_exec(cmd);

END;
@@
DELIMITER ; 

It's possible to use NEW.idLocation in my php file? I try some methods, but don't work.

8
  • add some explanation about your query Commented Mar 14, 2018 at 12:35
  • $sql ="SELECT txPostCode, id FROM users WHERE id=(SELECT idClient FROM sat_clientLocation where idLocation= NEW.idLocation)"; Commented Mar 14, 2018 at 12:37
  • It is not correct, i put idLocation= NEW.idLocation because there i want to use NEW.idLocation Commented Mar 14, 2018 at 12:37
  • 2
    What do you mean with "to use NEW.idLocation in my php file"? Could you add the PHP code you already have? Commented Mar 14, 2018 at 12:41
  • "I try some methods, but don't work." what doesnt work? Because sys_exec isn't a MySQL's out off the box function i believe there is a plugin for it.. You might need to use /usr/bin/php -f instead -f option stands for file execution. Commented Mar 14, 2018 at 14:05

1 Answer 1

0

According to that solution:

SET cmd=CONCAT('/usr/bin/php ', 
               '/var/www/html/poi/insertTest.php?location=' ,
               NEW.idLocation);

That will be passed to your script as $_GET[] variable:

<?php
echo $_GET['location'];
?>
Sign up to request clarification or add additional context in comments.

1 Comment

The php file is not seen by php exec. Why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.