Welcome Guest, Not a member yet? Register   Sign In
codeigniter 3.1.7 result query array has an issue
#7

(This post was last modified: 02-26-2018, 08:05 AM by dave friend.)

PHP Code:
$query  $this->db->query('MY_QUERY'); 

In the code above $query can end up being set to TRUE, FALSE, or a CI_DB_result object.

Read the Docs

There can be several reasons for a FALSE return, but it is usually because 'MY_QUERY' is invalid. That's what I usually do wrong anyway. Dodgy

Best practice would undoubtedly recommend checking the return of query() before attempting to use it. To be perfectly clear, you want to make sure it is a CI_DB_result object (or not a bool) before using it on a method like num_rows() and any of the result*() methods. For instance

PHP Code:
$query  $this->db->query('MY_QUERY');
if(
is_bool($query)
{
    
// respond to the problem
}
else
{
    return 
$query->result_array();

Reply


Messages In This Thread
RE: codeigniter 3.1.7 result query array has an issue - by dave friend - 02-26-2018, 07:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB