I don't know why, but this doesnt work.
array_unshift($params,$types);
if($stmt = $conn->prepare($sql)){
call_user_func_array(array($stmt, 'bind_param'), refValues($params));
$stmt->execute();
Now it says:
Warning: mysqli_stmt::bind_param() expects parameter 1 to be string, array given...
So what is wrong with this code?
function refValues($arr){
if(strnatcmp(phpversion(),'5.3') >= 0){ //Reference is required for PHP 5.3
$refs = array();
foreach($arr as $key => $value){
$refs[$key] = &$arr[$key];
}
return $refs;
}
return $arr;
}
The print_r of refValues($params);
Array ( [0] => Array ( [0] => i [1] => i [2] => i [3] => i [4] => i [5] => i [6] => i [7] => i [8] => i [9] => s [10] => i [11] => i [12] => i [13] => i [14] => i [15] => i [16] => i [17] => i [18] => i [19] => i [20] => i [21] => i ) [1] => 1 [2] => 0 [3] => 0 [4] => 0 [5] => 0 [6] => 0 [7] => 0 [8] => 1241 [9] => [10] => [11] => 1 [12] => [13] => [14] => [15] => 432 [16] => 243 [17] => 0 [18] => 0 [19] => 0 [20] => 0 [21] => 0 [22] => 78 )
Here's the solution:
I just had to implode the $types array. So Then the first parameter is a string and not an array anymore.
refValues($params).