codeigniter异常:对boolean上的成员函数num\u rows()的调用

jv4diomz  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(317)

请告诉我codeigniter有问题。当我尝试在这里登录时,结果是:
严重性:错误-->异常:在boolean/home/euroyals/bdhospitals.com/amar-pharmary/application/models/reports.php 276上调用成员函数numđrows()
在相对文件的代码下面:

public function out_of_stock_count(){

  $this->db->select("b.manufacturer_name,a.product_name,a.generic_name,a.strength,((select ifnull(sum(quantity),0) from product_purchase_details where product_id= `a`.`product_id`)-(select ifnull(sum(quantity),0) from invoice_details where product_id= `a`.`product_id`)) as 'stock'");
       $this->db->from('product_information a');
       $this->db->join('manufacturer_information b','b.manufacturer_id=a.manufacturer_id','left');
         $this->db->having('stock < 10');
         $this->db->group_by('a.product_id');
         return $records = $this->db->get()->num_rows();
tpxzln5u

tpxzln5u1#

这是因为get()要么返回 ResultInterface 或者 false (https://github.com/codeigniter4/codeigniter4/blob/e31166e246a7b27ba555897ef87b9812c9a01195/system/database/basebuilder.php#l1855)
万一 false 您不能对其调用num\u rows()(错误消息是这样说的)请尝试以下操作:

$result = $this->db->get();
return $result ? $result->num_rows() : 0;

相关问题