To display the query string:
print_r($this->db->last_query());
To display the query result:
print_r($query);
The Profiler Class will display benchmark results, queries you have run, and $_POST data at the bottom of your pages. To enable the profiler place the following line anywhere within your Controller methods:
$this->output->enable_profiler(TRUE);
Profiling user guide: https://www.codeigniter.com/user_guide/general/profiling.html