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.

er.irfankhan11
  • 1,280
  • 2
  • 16
  • 29
  • add some explanation about your query – er.irfankhan11 Mar 14 '18 at 12:35
  • $sql ="SELECT txPostCode, id FROM users WHERE id=(SELECT idClient FROM sat_clientLocation where idLocation= NEW.idLocation)"; – Isabella Popa Mar 14 '18 at 12:37
  • It is not correct, i put idLocation= NEW.idLocation because there i want to use NEW.idLocation – Isabella Popa Mar 14 '18 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? – simon Mar 14 '18 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. – Raymond Nijland Mar 14 '18 at 14:05
  • I have already installed the plugin. My problem is that i can't take the NEW.idLocation in my php code. – Isabella Popa Mar 14 '18 at 14:11
  • @IsabellaPopa, according to your query in comment, you should use `where in` – er.irfankhan11 Mar 14 '18 at 14:13
  • It is not working. My querry is now $sql ="SELECT txPostCode, id FROM users WHERE id=(SELECT idClient FROM sat_clientLocation where idLocation='".$_GET['location']."')"; – Isabella Popa Mar 14 '18 at 14:20

1 Answers1

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'];
?>
davidbaumann
  • 208
  • 2
  • 14