I have this code
public function bind_array($array) {
$array=[1,"bob"];
$type = '';
foreach ( $array as $var ) {
switch (true) {
case is_int ( $var ) :
$type .= "i";
break;
case is_double ( $var ) :
$type .= "d";
default :
$type .= "s";
}
}
$param_array [] = &$type;
for($i = 0; $i < count ( $array ); $i ++) {
$param_array [] = &$array [$i];
}
call_user_func ( array ($this->stmt,'bind_param' ), $param_array );
}
and I always get the error wrong parameter count. What is the mistake here?
If I change the last line into
call_user_func ( array ($this->stmt,'bind_param' ), 'is',1,"bob" );
Everything is ok.
Thanks for helping.
Just use call_user_func_array
instead of call_user_func
since you're passing an array.
call_user_func_array ( array ($this->stmt,'bind_param' ), $param_array );
Here are the official docs .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.