Whether you’re using the active record class or not, you can access database errors using $this->db->_error_message() and $this->db->_error_number().
If you’re using a mysql database, these functions are equivalent to mysql_error() and mysql_errno() respectively. You can check out these functions by looking at the source code for the database driver for the database you’re using. They’re located in system/database/drivers.
So, after you run a query, you can check for errors using something like:
if ($this->db->_error_message()) \\handle error