baranq baranq - 1 year ago 70
MySQL Question

Check codeigniter query errors instead of showing them to the user

How can I check if a query went wrong instead of showing errors to users (containing database info which is unsafe).

Let's say I have such situation where my paging class takes a URI segment to show page
. If someone write it like this
I get an error that shows information about my database.

How can I handle this?

Answer Source

In application/config/database.php set

// suppress error output to the screen
$db['default']['db_debug'] = FALSE;

In your model or controller:

// try the select.
$dbRet = $this->db->select($table, $dataArray);
// select has had some problem.
if( !$dbRet )
   $errNo   = $this->db->_error_number()
   $errMess = $this->db->_error_message();
   // Do something with the error message or just show_404();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download