Hi,
Beforehand, I had a method which allows the user to specify a mysqli connection, a query string with '?' to avoid SQL injection, and an array of parameters. It would then dynamically bind the params and output the result as an associative array.
Now I've moved the parameter binding part out into a separate method as I'm adding more implementations for it. The issue now is:
call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object
This is the method:
private static function bind_dynamic_params(&$stmt, $params)
{
$param_types = str_repeat('s', count($params));
$param_bind_names[] = $param_types;
for($i = 0; $i < count($params); $i++)
{
$param_bind_name = 'bind' . $i;
$$param_bind_name = $params[$i];
$param_bind_names[] = &$$param_bind_name;
}
call_user_func_array(array($stmt, 'bind_param'), $param_bind_names);
}
I'm looking to pass the $stmt object by reference so
call_user_func_array can be called on it, while the original method can use this altered object.
The way I'm trying to do this is:
1. $conn = new mysqli(...); $stmt = $conn->prepare($query);
2. bind_dynamic_params($stmt, $params);
3. Continue using $stmt now, such as ->execute() or ->close().
What I have tried:
Passing by reference, looking online for around half an hour