Just a few words to explain what I want to do.
I want to extend my lib with a function able to call stored procedures. I found here the steps to make it but I have a hard time to make it generic.
To achieve this, I've read that I have to use the call_user_func_array on mysqli_stmt_bind_param because I know only at execution the number of parameters IN, there types and the number of OUT
Here a few details of what I've done:
- create a connection to the DB
- set the charset
- build the call string for example CALL (?,?,?,@outParam1,@outParam2)
- prepare the call string
- build an array of parameters to use with call_user_func_array that will call mysqli_stmt_bind_param <= this what give's me troubles
- call mysql_stmt_excute
- finally, make a select to get out parameters.
Here the main parts of code :
function executeProc($sProcName, $sInParamTypes, $aInParam, $iNumberParameterOut=0)
{
$oConnection = @mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DBNAME);
mysqli_set_charset($oConnection, "utf8");
/* code to build the $sCallStr */
$oMysqlCall = mysqli_prepare($oConnection, $sCallStr);
array_unshift($aFunctionParam, $oMysqlCall, $sInParamTypes);
$aFunctionParam = array_merge($aFunctionParam, $aInParam);
call_user_func_array("mysqli_stmt_bind_param", $aFunctionParam);
mysqli_stmt_execute($oMysqlCall);
}
the return of call_user_func_array is NULL. I've tryed to call the function manualy :
mysqli_stmt_bind_param($aFunctionParam[0], $aFunctionParam[1], $aFunctionParam[2], $aFunctionParam[3], $aFunctionParam[4], $aFunctionParam[5], $aFunctionParam[6], $aFunctionParam[7]);
And it works. I see the result in the DB and the return of the function is TRUE. Can someone help here? Is there another way to pass the array of parameters? (like by reference ?)
Thx a lot for your help