how to execute a procedure with parameter in php

0

I need to execute a procedure sending a parameter by php but is not returning follow the code below:

//código em PHP
$figura =  mysqli_query($conexao,"CALL 'spare_change'.'boxlabel'('".$template."')") or die("erro no update");

//A Procedure Criada
CREATE DEFINER='root'@'%' PROCEDURE 'boxlabel'(template varchar(20))
BEGIN

-- update prom.label_template set label_tpl_content = replace(label_tpl_content, ' eJz', 'eJz') where label_tpl_name = @template;
select * from prom.label_template where label_tpl_name = @template;

END

Where is the error in the code?

    
asked by anonymous 14.06.2018 / 15:59

1 answer

0

You can run a query before to define a variable for the procedure, and then use that variable in the call.

mysqli_query($conexao, "SET @template = '" . $template . "'");
$figura =  mysqli_query($conexao,"CALL 'spare_change'.'boxlabel'(@template)") or die("erro no update");

But in addition, in the procedure itself, -- is causing update to be just a comment line.

Try to remove -- from the beginning of this line, otherwise this code will not be executed.

-- update prom.label_template set label_tpl_content = replace(label_tpl_content, ' eJz', 'eJz') where label_tpl_name = @template;
    
14.06.2018 / 16:21