difference between $query>num_rows() and $this->db->count_all_results() in CodeIgniter & which one is recommended

后端 未结 8 1671
南方客
南方客 2020-12-13 17:50

In a scenario I need to know the count of recordset a query will return, which in codeigniter can be done by $query->num_rows() or $this->db->cou

相关标签:
8条回答
  • 2020-12-13 18:41
    $sql = "select count(*) as row from login WHERE firstname = '" . $username . "' AND password = '" . $password . "'";
        $query = $this->db->query($sql);
        print_r($query);exit;
        if ($query->num_rows() == 1) {
        return true;
        } else {
        return false;
        }
    
    0 讨论(0)
  • 2020-12-13 18:42

    We can also use

    return $this->db->count_all('table_name');  
    

    or

    $this->db->from('table_name');
    return $this->db->count_all_result();
    

    or

    return $this->db->count_all_result('table_name');
    

    or

    $query = $this->db->query('select * from tab');  
    return $query->num_rows();
    
    0 讨论(0)
提交回复
热议问题