[eluser]Jonny Noog[/eluser]
Hi,
Just trying to work out if it's possible to log database errors to the log file but at the same time not have them appear in the browser. My tests so far would seem to suggest that if you set $db['default']['db_debug'] = FALSE; in database.php, it will stop database errors from appearing in the browser as expected, but this also appears to make calls to $this->db->_error_message() and $this->db->_error_number() produce null values when I try to use these methods in conjunction with a database transaction.
Some test code:
Code:
$this->db->trans_start();
$this->db->query("INSERT INTO `users` (`foo`) VALUES ('bar')"); // Generates an unknown column error
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE)
{
$err_msg = $this->db->_error_message();
$err_num = $this->db->_error_number();
log_message('error', 'Database error: ' . $err_msg . 'Error number: ' . $err_num);
show_error('A database error has occured.');
exit();
}
The message 'A database error has occured.' appears in the browser but in the log file, I get:
Quote:ERROR - 2009-06-23 09:19:28 --> Database error: Error number: 0
So it appears that $err_msg and $err_num are not being set to anything meaningful.
If I set $db['default']['db_debug'] = TRUE; in database.php, I get the unknown column error logged in the log file like so:
Quote:ERROR - 2009-06-23 09:31:00 --> Query error: Unknown column 'foo' in 'field list'
But I also get the error being output to the browser.
Does anyone know of a way that I can have database errors logged to the log file but not display them in the browser?