Welcome Guest, Not a member yet? Register   Sign In
num_rows() problem in the count_all_results
#1

Hi guys,

I use the count_all_result function, and if I set a non existent column name in WHERE clause, then throw an error.
In the WHERE clause have dynamic column name, so incorrect column names may occur

Code:
$this->db->select('column_1');
$this->db->where('nonexist_col', 'anything');
$count = $this->db->count_all_results('table');

Error: Call to a member function num_rows() on a non-object
This is in the count_all_results function of DB_query_builder.

Code:
public function count_all_results($table = '', $reset = TRUE)
{
        ...
    ...

    if ($result->num_rows() === 0)
    {
        return 0;
    }
Because the query string wrong, the $result will have no num_rows function.
Here is a possible solution, but I don't want to overwrite the CI code:

Code:
if(is_object($result)){
        if ($result->num_rows() === 0)
    {
       return 0;
    }
}
else{
    return FALSE;
}

Is there any good solution for this?
Reply


Messages In This Thread
num_rows() problem in the count_all_results - by CodeArt - 02-06-2019, 08:46 AM



Theme © iAndrew 2016 - Forum software by © MyBB