One thing to take into consideration.
sql_exec_sql() macro is for SQL sentences don’t returning anything.
For clarification take a look into this.
Create this 2 procedures into your database:
DELIMITER $$
DROP PROCEDURE IF EXISTS `sp_output_select`$$
CREATE PROCEDURE `sp_output_select`(IN IN_param VARCHAR(15), OUT OUT_param1 VARCHAR(15))
BEGIN
SET OUT_param1 = CONCAT('OUT ', IN_param);
SELECT IN_param;
END$$
DROP PROCEDURE IF EXISTS `sp_somevar`$$
CREATE PROCEDURE `sp_somevar`(IN IN_param VARCHAR(15), OUT OUT_param1 VARCHAR(15))
BEGIN
SET OUT_param1 = CONCAT('OUT ', IN_param);
END$$
DELIMITER ;
Now create a blank application, paste this code, and execute it:
/*
Store procedure with output into a var
*/
echo '********************** Store procedure with output into a var **********************<br>';
echo '$qry = "CALL sp_somevar(\'IN Text\', @out_param)"';
echo '<br>';
$qry = "CALL sp_somevar('Test', @out_param)";
echo 'sc exec_sql($qry) <- First underscore is omitted because SC is parsing it inside echo';
echo '<br>';
sc_exec_sql($qry);
echo '<br>';
echo "<br>OUTPUT:<br>";
echo "We can't output because exec_sql don't returns anything.";
echo '<br>';
echo '<br>';
echo "What happens if we use sc lookup?.";
echo '<br>';
sc_lookup(arr_qry, $qry);
echo "<br>OUTPUT:<br>";
var_dump($arr_qry);
echo " <br> ************* <br>";
echo '<br>';
echo "With lookup either, because we are bounding the output to a MySQL user var, and we have to SELECT it, then....";
echo '<br>';
$qry = "SELECT @out_param";
sc_lookup(arr_qry, $qry);
echo '$qry = "SELECT @out_param";<br>
sc lookup(arr_qry, $qry);';
echo "<br>OUTPUT:<br>";
var_dump($arr_qry);
echo " <br> ************* <br>";
echo '<br>';
echo "Now, we can see the output.";
echo '<br>';
echo '******************************************************************<br>';
echo '********************** Store procedure with output into a var and SELECT **********************<br>';
echo '$qry = "CALL sp_output_select(\'Other test\', @other_out_param)"';
echo '<br>';
$qry = "CALL sp_output_select('IN Text', @other_out_param)";
echo 'sc lookup(arr_qry, $qry);<br>';
sc_lookup(arr_qry, $qry);
echo "<br>OUTPUT:<br>";
var_dump($arr_qry);
echo " <br> ************* <br>";
$qry = "SELECT @other_out_param";
sc_lookup(arr_qry, $qry);
echo '$qry = "SELECT @other_out_param";<br>';
echo "<br>OUTPUT:<br>";
var_dump($arr_qry);
echo " <br> ************* <br>";
I hope now it’s clear.