CODEIGNITER 异常:在布尔值上调用成员函数 num_rows()

CODEIGNITER Exception: Call to a member function num_rows() on boolean

我对 codeigniter 有疑问。当我尝试在这里登录时,结果是:

严重性:错误 --> 异常:在布尔值 /home/euroyals/bdhospitals.com/amar-pharmacy/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();

这是因为 get() returns a ResultInterfacefalse (https://github.com/codeigniter4/CodeIgniter4/blob/e31166e246a7b27ba555897ef87b9812c9a01195/system/Database/BaseBuilder.php#L1855)

false 的情况下,您不能对其调用 num_rows() (这是错误消息所说的) 尝试这样的事情:

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