I'm trying to dinamically pass some variables to mysqli_stmt::bind_param()
, but I'm stuck (probably is there a problem even with call_user_func_array
):
[..]
else if($_SESSION['status']==2){
$merge=array('type'=>array(),'val'=>array());
$tail=array();
if($id!=''){
$tail[]='`user_id`=?';
$merge['type'][]='i';
$merge['val'][]=$id;
}
if($enid!=''){
$tail[]='`ref_id`=?';
$merge['type'][]='s';
$merge['val'][]=$enid;
}
if($tit!=''){
$tail[]='`title`=?';
$merge['type'][]='s';
$merge['val'][]=$tit;
}
if($dep!=''){
$tail[]='`department_id`=?';
$merge['type'][]='i';
$merge['val'][]=$dep;
}
if($opid!=''){
$tail[]='`operator_id`=?';
$merge['type'][]='i';
$merge['val'][]=$opid;
}
if($op!=''){
$tail[]='`operator_id` IN (SELECT `id` FROM '.$SupportUserTable.' WHERE `name`=? AND 0!=`status`)';
$merge['type'][]='s';
$merge['val'][]=$op;
}
if($from!=''){
$tail[]='`created_time` <= ?';
$merge['type'][]='s';
$merge['val'][]=$from;
}
if($to!=''){
$tail[]='`created_time` >= ?';
$merge['type'][]='s';
$merge['val'][]=$to;
}
if($usmail!=''){
$tail[]='(user_id=(SELECT `id` FROM '.$SupportUserTable.' WHERE `mail`=? LIMIT 1) OR operator_id=(SELECT `id` FROM '.$SupportUserTable.' WHERE `mail`=? LIMIT 1))';
$merge['type'][]='ss';
$merge['val'][]=$usmail.','.$usmail;
}
$query.=implode(' AND ',$tail);
}
$prepared = $stmt->prepare($query);
if($prepared){
if(call_user_func_array(array($stmt, "bind_param"), array(implode('',$merge['type']), $merge['val']) )){
[...]
This is the error:
PHP Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given in C:\xampp\htdocs\php\function.php on line 2165
All the varibles has been decalered before this piece of code and are correct.
I have tried to add the &
before the variable(example:$merge['val'][]=&$id;
), but it says that is an unexpected character ( I expected this error, 'cause I have no idea of what I was doing)
Thanks in advance