How can you print SQL statement in CodeIgniter model?

$this>db>insertid();

In CodeIgniter, to print the SQL statement generated by a query within a model, you can use the last_query() method. This method returns the SQL query string of the last database operation performed.

Here’s how you can use it:

php
$query = $this->db->get('my_table');
echo $this->db->last_query();

This will print the SQL query generated by the get() method on the 'my_table' table. You can use this method after any database operation (insert(), update(), delete(), etc.) to see the corresponding SQL statement.