• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to gracefully degrade SQL errors

#1
Hi all,

If I get an SQL error I'd like to log it and redirect the user to an error page which just informs them there has been an error.

The code I have tried below doesn't work (log_message doesn't work, the page isn't redirected and I just get the "Database Error Occurred" page.  The error (not the log_message part) is written to my log.

Where am I going wrong please?

Code:
// UPDATE
$this->db->where('fr_mach_date', $_POST['hdnMatchDate']);
$this->db->where('fr_team_code', $side);
$this->db->where('fr_double_banker', $double_banker_from);
if (!$this->db->update('fixtures_results', $arr_match_info))
//error updating the row.
{
log_message('error', 'Error updating fixture '.$_POST['hdnFixture_'.$side]);
#$error = $this->db->error();
redirect('week_fixtures/error');
}
Reply

#2
I found the answer.  For those who also encounter this problem, you need to change 'development' to 'production' for the environment at the top of your index.php page.  

PHP Code:
*---------------------------------------------------------------
 * 
APPLICATION ENVIRONMENT
 
*---------------------------------------------------------------
 *
 * 
You can load different configurations depending on your
 
current environmentSetting the environment also influences
 
things like logging and error reporting.
 *
 * 
This can be set to anythingbut default usage is:
 *
 * 
    development
 
    testing
 
    production
 
*
 * 
NOTE: If you change thesealso change the error_reporting() code below
 
*/
    
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'production'); 
Reply

#3
And/or actually look at your database configuration and see that there's an option for this.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.