I have a sql statement in my model,
I then say
$query = $this->db->query($sql, array(fields, fields1); if ($query) { return true: } else {
You can use this:
$this->db->last_query();
"Returns the last query that was run (the query string, not the result)."
Reff: https://www.codeigniter.com/userguide3/database/helpers.html