Parameter 2 to mysqli_stmt::bind_param() expected to be a reference
2014-10-10 19:37
211 查看
今天在用brophp(是lamp兄弟连里的一个框架),写程序的时候,老是报一个错误,具体情况是这样的
Php代码
![](https://oscdn.geek-share.com/Uploads/Images/Content/201912/11/44d12deced8ebc698f671a095f1864d3.png)
if(emptyempty($_GET['id'])) $this->error('数据不存在');
$c = D('news');
$id = $_GET['id'];
$num = $c->total();
$page = new Page($num,10);
$data = $c->where(array('categoryid'=>$id))->limit($page->limit)->select();
/*问题就出在这个地方了,我加了这个where条件,它就报错,如果不加,就正常,而且在报错的时候 调试信息里打印的时候sql语句,我在phpmyadmin里执行了下,也正常,可以查到数据,也就是说sql语句是没有问题的,后来在论坛里找到了方法与原因,看下面*/
$this->assign('p',$page->fpage());
$this->assign('data',$data);
//P($da);
$this->display('index/nlist');
运行时警告[在文件 H:\aphp\BroPHPTest\brophp\bases\dmysqli.class.php 中,第 75 行]:Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given
SQL ERROR: [0] No data supplied for parameters in prepared statement
这个是它提示的错误,按照提示,找到dmysqli.class.php的75行。它的代码是
Php代码
![](https://oscdn.geek-share.com/Uploads/Images/Content/201912/11/44d12deced8ebc698f671a095f1864d3.png)
call_user_func_array(array($stmt, 'bind_param'),$value);
换成
Php代码
![](https://oscdn.geek-share.com/Uploads/Images/Content/201912/11/44d12deced8ebc698f671a095f1864d3.png)
call_user_func_array(array($stmt, 'bind_param'), self::refValues($value));
然后,在这个文件里的其它地方,添加上这段代码
Php代码
![](https://oscdn.geek-share.com/Uploads/Images/Content/201912/11/44d12deced8ebc698f671a095f1864d3.png)
function refValues($arr){
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
$refs = array();
foreach($arr as $key => $value)
$refs[$key] = &$arr[$key];
return $refs;
}
return $arr;
}
根据最后的这个函数,觉得这个应该和php的版本有关,所以暂时记录下吧。
Php代码
![](https://oscdn.geek-share.com/Uploads/Images/Content/201912/11/44d12deced8ebc698f671a095f1864d3.png)
if(emptyempty($_GET['id'])) $this->error('数据不存在');
$c = D('news');
$id = $_GET['id'];
$num = $c->total();
$page = new Page($num,10);
$data = $c->where(array('categoryid'=>$id))->limit($page->limit)->select();
/*问题就出在这个地方了,我加了这个where条件,它就报错,如果不加,就正常,而且在报错的时候 调试信息里打印的时候sql语句,我在phpmyadmin里执行了下,也正常,可以查到数据,也就是说sql语句是没有问题的,后来在论坛里找到了方法与原因,看下面*/
$this->assign('p',$page->fpage());
$this->assign('data',$data);
//P($da);
$this->display('index/nlist');
运行时警告[在文件 H:\aphp\BroPHPTest\brophp\bases\dmysqli.class.php 中,第 75 行]:Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given
SQL ERROR: [0] No data supplied for parameters in prepared statement
这个是它提示的错误,按照提示,找到dmysqli.class.php的75行。它的代码是
Php代码
![](https://oscdn.geek-share.com/Uploads/Images/Content/201912/11/44d12deced8ebc698f671a095f1864d3.png)
call_user_func_array(array($stmt, 'bind_param'),$value);
换成
Php代码
![](https://oscdn.geek-share.com/Uploads/Images/Content/201912/11/44d12deced8ebc698f671a095f1864d3.png)
call_user_func_array(array($stmt, 'bind_param'), self::refValues($value));
然后,在这个文件里的其它地方,添加上这段代码
Php代码
![](https://oscdn.geek-share.com/Uploads/Images/Content/201912/11/44d12deced8ebc698f671a095f1864d3.png)
function refValues($arr){
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
$refs = array();
foreach($arr as $key => $value)
$refs[$key] = &$arr[$key];
return $refs;
}
return $arr;
}
根据最后的这个函数,觉得这个应该和php的版本有关,所以暂时记录下吧。
相关文章推荐
- mysqli::stmt报Fatal error: Call to a member function bind_param() on a non-object in ...
- Name for parameter binding must not be null or empty! On JDKs < 8, you need to use @Param for named
- /lib/libmysqlcppconn.so: undefined reference to `mysql_stmt_execute@libmysqlclient_18' 解决方法
- JDBC连接执行 MySQL 存储过程报权限错误:User does not have access to metadata required to determine stored procedure parameter types. If rights can not be granted,
- MySQL安装出现的问题:the security settings could not be applied to 。。。 原因是原来的东西没有卸载干净
- eclipse中如何去除警告:Class is a raw type. References to generic type Class<T> should be parameterized
- Cannot be serialized to JSON because its IsReference setting is 'True'
- MySQL connector C++在Linux下编译undefined reference to 'get_driver_instance'问题
- "WorldClient was expected to be running but wasn't;"解决方法
- Error: initial value of reference to non const must be lvalue 原因以及解决方法
- (.text+0x11): undefined reference to `mysql_init'
- ORA-02069: global_names parameter must be set to TRUE for this operation
- Warning: mysql_query() expects parameter 2 tobe resource, object given i
- 关于:ORA-02069: global_names parameter must be set to TRUE for this operation
- Expected one result (or null) to be returned by...
- Exception : The underlying connection was closed: A connection that was expected to be kept alive was closed by the server
- 【ERROR_2】Call to a member function bind_param() on a non-object
- What To Do If mysql Cannot Be Found
- 关于:ORA-02069: global_names parameter must be set to TRUE for this operation
- MySQL :: MySQL 5.0 Reference Manual :: 20.6.16.1 Problems Linking to the MySQL Client Library