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

邮差的信 提交于 2020-02-24 05:12:04

问题


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


回答1:


I figured out the problem. I have to write a statement just above my query i.e:

$this->db->save_queries = TRUE;

After this write your query and than write $this->db->last_query(); it is showing the last query now.

Sample:

$this->db->save_queries = TRUE;
$str = $this->db->last_query();
echo $str;

Cheers.




回答2:


I want to ask why are printing query like array simply use

$str = $this->db->last_query();
echo $str; 


来源:https://stackoverflow.com/questions/45363375/cant-get-result-from-this-db-last-query-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!