Can't get result from $this->db->last_query(); codeigniter

Viewed 7494

Quite a simple thing to ask and must be discussed many times, but I still not able to get the result of $this->db->last_query();.

            $this->db->select('count(*) as totalverified,res_sales.upduser, employee.name');
        $this->db->from('res_sales');
        $this->db->join('employee','employee.user_id = res_sales.upduser');
        $this->db->where('date>=', $fromdate);
        $this->db->where('date<=', $todate);
        $this->db->where('verificationnumber<>', '');
        $this->db->where('verificationnumber<>', NULL);
        $this->db->group_by('res_sales.upduser');
        $this->db->group_by('employee.name');
        $q = $this->db->get();
        $str = $this->db->last_query();
        print_r($str);
        if ($q->num_rows() > 0)
        {
            return $q->row();
        }

        return FALSE;

Above is the code in my model function. I am not able to get the result as expected to want to see what the query is being run at backend.

Thanks. Danish

3 Answers

Create a helper function and use it anywhere in your project:

function lq(){  echo $this->db->last_query(); die; }

and call to controller and model like:

lq();
Related