PHP致命错误:在中的布尔值上调用成员函数num_rows()
我已将我的网站从一个服务器移动到另一个服务器,当我尝试访问测验结果页面时出错。 错误是: 无法处理此请求 在查看我的php错误日志后,我发现这一行:PHP致命错误:在中的布尔值上调用成员函数num_rows(),php,codeigniter,Php,Codeigniter,我已将我的网站从一个服务器移动到另一个服务器,当我尝试访问测验结果页面时出错。 错误是: 无法处理此请求 在查看我的php错误日志后,我发现这一行: [09-May-2019 08:19:13 Asia/Kolkata] PHP Fatal error: Call to a member function num_rows() on boolean in /home/USER/public_html/PATH/PATH/models/Result_model.php on line 143
[09-May-2019 08:19:13 Asia/Kolkata] PHP Fatal error: Call to a member
function num_rows() on boolean in
/home/USER/public_html/PATH/PATH/models/Result_model.php on line
143
这是文件内容的主要部分,注意到我在第143行中的注释如下:
function get_result($rid){
$logged_in=$this->session->userdata('logged_in');
$uid=$logged_in['uid'];
if($logged_in['su']=='0'){
$this->db->where('savsoft_result.uid',$uid);
}
$this->db->where('savsoft_result.rid',$rid);
$this->db->join('savsoft_users','savsoft_users.uid=savsoft_result.uid');
$this->db->join('savsoft_group','savsoft_group.gid=savsoft_users.gid');
$this->db->join('savsoft_quiz','savsoft_quiz.quid=savsoft_result.quid');
$query=$this->db->get('savsoft_result');
return $query->row_array();
}
function last_ten_result($quid){
$this->db->order_by('percentage_obtained','desc');
$this->db->limit(10);
$this->db->where('savsoft_result.quid',$quid);
$this->db->join('savsoft_users','savsoft_users.uid=savsoft_result.uid');
$this->db->join('savsoft_quiz','savsoft_quiz.quid=savsoft_result.quid');
$query=$this->db->get('savsoft_result');
return $query->result_array();
}
function get_percentile($quid,$uid,$score){
$logged_in =$this->session->userdata('logged_in');
$gid= $logged_in['gid'];
$res=array();
$this->db->where("savsoft_result.quid",$quid);
$this->db->group_by("savsoft_result.uid");
$this->db->order_by("savsoft_result.score_obtained",'DESC');
$query = $this -> db -> get('savsoft_result');
$res[0]=$query -> num_rows(); // THIS IS LINE 143
$this->db->where("savsoft_result.quid",$quid);
$this->db->where("savsoft_result.uid !=",$uid);
$this->db->where("savsoft_result.score_obtained <=",$score);
$this->db->group_by("savsoft_result.uid");
$this->db->order_by("savsoft_result.score_obtained",'DESC');
$querys = $this -> db -> get('savsoft_result');
$res[1]=$querys -> num_rows();
return $res;
函数获取结果($rid){
$logged_in=$this->session->userdata('logged_in');
$uid=$logged_in['uid'];
如果($logged_in['su']='0'){
$this->db->where('savsoft\u result.uid',$uid);
}
$this->db->where('savsoft\u result.rid',$rid);
$this->db->join('savsoft_users','savsoft_users.uid=savsoft_result.uid');
$this->db->join('savsoft_group','savsoft_group.gid=savsoft_users.gid');
$this->db->join('savsoft\u quick','savsoft\u quick.quid=savsoft\u result.quid');
$query=$this->db->get('savsoft_result');
返回$query->row_array();
}
函数最后十次结果($quid){
$this->db->order_by('percentage_acquired','desc');
$this->db->limit(10);
$this->db->where('savsoft\u result.quid',$quid);
$this->db->join('savsoft_users','savsoft_users.uid=savsoft_result.uid');
$this->db->join('savsoft\u quick','savsoft\u quick.quid=savsoft\u result.quid');
$query=$this->db->get('savsoft_result');
返回$query->result_array();
}
函数get_百分位数($quid,$uid,$score){
$logged_in=$this->session->userdata('logged_in');
$gid=$logged_in['gid'];
$res=array();
$this->db->where(“savsoft\u result.quid”,$quid);
$this->db->group_by(“savsoft_result.uid”);
$this->db->order_by(“savsoft_result.score_govered”,'DESC');
$query=$this->db->get('savsoft_result');
$res[0]=$query->num_rows();//这是第143行
$this->db->where(“savsoft\u result.quid”,$quid);
$this->db->where(“savsoft\u result.uid!=”,$uid);
$this->db->where(“savsoft\u result.score\u获得的正如我们在聊天中讨论的,这个问题是由服务器迁移和使用默认启用的MySQL 5.7+的新服务器引起的
原因是MySQL无法选择与分组相关的行列式值,并且会出现错误,而不是像在以前的MySQL版本中那样,在select
语句中默默忽略可能不需要的值。
例如:按采购日期从订单组中选择客户、金额(订单总额)
如果两个或多个客户具有相同的购买日期
,则只能显示一个,MySQL需要确定您想要哪一个
由于CodeIgniter在使用$this->db->get()
时默认为语句使用SELECT*
,因此会遇到错误
要解决此问题,强烈建议在整个应用程序中更新GROUP BY
相关查询的所有,使其与MySQL 5.7兼容。这将确保您从GROUP BY
语句中检索到正确的值
您可以使用几个选项,按最不复杂和最有益的顺序排列
1)使用而不是$query->num\u rows()
(又名:选择计数(*)
)
3)为所有未分组的列明确定义
(这相当于通过
仅禁用完整组)
使用我上面提供的查询
SELECT ANY_VALUE(customer), SUM(order_total) FROM orders GROUP BY purchase_date
因此,您应该能够使用如下内容,确保在相关表中添加所有未分组的列
$this->db->select('ANY_VALUE(savsoft_result.quid), ANY_VALUE(savsoft_result.score_obtained), savsoft_result.uid');
$this->db->where("savsoft_result.quid",$quid);
$this->db->group_by("savsoft_result.uid");
$this->db->order_by("savsoft_result.score_obtained",'DESC');
$query = $this -> db -> get('savsoft_result');
$res[0] = $query->num_rows();
$this->db->select('ANY_VALUE(savsoft_result.quid), ANY_VALUE(savsoft_result.score_obtained), savsoft_result.uid');
$this->db->where("savsoft_result.quid",$quid);
$this->db->where("savsoft_result.uid !=",$uid);
$this->db->where("savsoft_result.score_obtained <=",$score);
$this->db->group_by("savsoft_result.uid");
$this->db->order_by("savsoft_result.score_obtained",'DESC');
$querys = $this->db->get('savsoft_result');
$res[1] = $querys->num_rows();
这将检索当前使用的sql\u模式
并按
部分删除ONLY\u FULL\u GROUP\u,然后删除剩余的任何前导或尾随逗号。但是,一旦MySQL服务重新启动,您将需要再次执行该语句
要确保重新启动MySQL服务时,only_full_group_by
不会恢复为enabled,请编辑my.cnf
MySQL配置文件,在sql\u模式
声明中省略only_full_group_by
您可以通过执行语句来检索当前的sql\u模式
SHOW VARIABLES LIKE 'sql_mode';
它应该返回如下内容:
ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_VALUE_ON_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
复制整个文本,然后在my.cnf
文件中声明sql\u模式,删除ONLY\u FULL\u GROUP\u BY
部分
[mysqld]
sql_mode=ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_VALUE_ON_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
对my.cnf
文件进行更改后,重新启动MySQL服务。它是什么:函数num\u rows()
不存在或num\u rows()
on boolean?您的问题有相互冲突的问题陈述。如果是前者,请仔细检查您复制的系统文件夹是否正确。如果是后者,则表示您的查询失败(返回false而不是object);检查以确保数据库复制正确。数据库工作正常,网站中的所有内容都正常。出现此问题时未对网站进行任何更改。PHP错误日志显示文件有行错误。函数num_rows()已存在。您引用的日志文件似乎是一个旧的打字错误,db->num_rows()
,因为db->get()
返回的结果。当前错误表示返回的查询是true或false,而不是codeigniter的I am noob。我使用了:$res[0]=$this->db->num rows();所以我遇到了这个问题:调用未定义的方法CI_DB_mysqli_driver::num_rows(),但是您列出的代码是$query->num_rows()
,这是正确的…而DB->num_rows不是
SHOW VARIABLES LIKE 'sql_mode';
ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_VALUE_ON_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqld]
sql_mode=ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_VALUE_ON_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION