douyu1990 2012-10-30 08:09
浏览 67
已采纳

mysqli - mysqli_stmt :: bind_param()应该是一个参考

This is my class code:

class DAL
{

public function paramtypez($val)
{
        $types = '';                        //initial sting with types
        foreach($val as $para) 
        {     
            if(is_int($para)) {
                $types .= 'i';              //integer
            } elseif (is_float($para)) {
                $types .= 'd';              //double
            } elseif (is_string($para)) {
                $types .= 's';              //string
            } else {
                $types .= 'b';              //blob and unknown
            }
        }
        return $types;
}

 public function execsql($query,$param)
{
    $conn=new mysqli("127.0.0.1","root","","sample");

    if($row=$conn->prepare($query))
    {
        array_unshift($param,array(DAL::paramtypez($param)));
        call_user_func_array(array($row, 'bind_param'), $param);

        $row->execute();
        return true;
    }
    else
    return false;

}
}

and is use this class like this:

$vars = new DAL();
$vars->execsql('insert into tesst (name,family,age) values(?,?,?)',array('mori','gre','25'));

but that's return me this error:

 Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given in ..\htdocs\inc.php on line 30

how can fix this error? thanks for any help

  • 写回答

2条回答 默认 最新

  • doujia6433 2012-10-30 08:24
    关注

    $param looks like this right before you pass it to call_user_func_array:

    [['ssi'],'mori','gre','25']
    

    This is incorrect. You should change this:

    array_unshift($param,array(DAL::paramtypez($param)));
    

    To this:

    array_unshift($param,DAL::paramtypez($param));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛