我正在尝试将一些变量动态传递给mysqli_stmt::bind_param()
,但我被卡住了(即使使用 也可能存在问题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']) )){
[...]
这是错误:
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
在这段代码之前,所有变量都已被 decaler 并且是正确的。我试图&
在变量之前添加(例如:)$merge['val'][]=&$id;
,但它说这是一个意外的字符(我预计会出现这个错误,因为我不知道我在做什么)
提前谢谢