I have a sql statement in my model,
I then say
$query = $this->db->query($sql, array(fields, fields1); if ($query) { return true: } else {
Add this line right after the query you want to print.
Example:
$query = $this->db->query('SELECT * FROM table WHERE condition');
//Add this line.
var_dump($this->db->last_query());
exit();
or
echo $this->db->last_query();