In MySQL “DELETE FROM TABLE” returns 0 affected rows. The database
class has a small hack that allows it to return the correct number of
affected rows. By default this hack is enabled but it can be turned off
in the database driver file.

$this->db->last_query()

Returns the last query that was run (the query string, not the result).
Example:

$str=$this->db->last_query();// Produces: SELECT * FROM sometable....

Note

Disabling the save_queries setting in your database
configuration will render this function useless.