30 May 2017

CodeIgniter's last_query()

I had an issue running codeigniter's $this->db->last_query().

It returns the last query that was run (the query string, not the result). But, remember to run the query, ie call the get() method before the last_query() method.


// Some query you are having trouble building...
// note, you have to call get()
$query = $this->db->get();
echo $this->db->last_query(); // output the converted MySQL query 

This method is helpful when having trouble building queries with the CI query class.

No comments:

Post a Comment