Question

I am trying to use Database trigger and procedure to send sms I have create the table and I can insert data by:

use sms;  
INSERT INTO sms_out (id, sender,receiver,msg) 
     VALUES ('','MyName','25578200000',"test");

I have created trigger as;

use sms;  
CREATE TRIGGER push_message_trigger AFTER INSERT ON sms_out  
FOR EACH ROW  
CALL push_message(NEW.sender, NEW.receiver, NEW.msg);  

and I have created procedure as;

use sms;
DELIMITER $$

CREATE PROCEDURE push_message
    (p1 TEXT,
     p2 DOUBLE,
     p3 TEXT)
BEGIN

     DECLARE cmd CHAR(255);
     DECLARE result CHAR(255);
     SET cmd = CONCAT('curl "http://www.sms.co.tz/api.php?do=sms&username=Myusername&password=MyPassword&senderid=MyName&dest=25571500000&msg=test"');
      SET result = sys_eval(cmd);

END$$;

The above does not work but if I replace

SET cmd = CONCAT('curl "http://www.sms.co.tz/api.php?do=sms&username=Myusername&password=MyPassword&senderid=MyName&dest=25571500000&msg=test"');

With

SET cmd = CONCAT('touch /var/lib/mysql/Advo');

It works!!

Whats wrong with curl??

Was it helpful?

Solution

I guess the problem it's not the curl literal is how are you using mysql CONCAT funcion.

  • To concat strings you should do something like (if you don't use commas you aren't concatening strings):

    CONCAT(str1, str2, ....);

  • Seems that the problem are the quotes, try to escape the double quotes like this \"

* Show the error if you want people to know what's really happening

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top