0

我正在尝试将一些变量动态传递给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;,但它说这是一个意外的字符(我预计会出现这个错误,因为我不知道我在做什么)
提前谢谢

4

1 回答 1

1

查看我编写的扩展 mysqli 的 better_mysqli.php 类中的代码。它完全符合您的要求: better_mysqli.php

这个页面显示了它的基本用法:basic_usage.php

此页面显示详细用法:detailed_usage.php

于 2013-07-24T18:33:13.893 回答