Method of forbidding A Database Error Occurred error prompt in Codeigniter

  • 2021-06-29 10:26:32
  • OfStack

By default, CodeIgniter displays all PHP errors.But when you finish developing the program, you may want to change that.
You will find this function error_at the top of the index.php filereporting(), which allows you to set incorrect settings.Even if you turn off error reporting, error logging does not stop when an error occurs.
Therefore, modifying php.ini will not achieve the desired effect.

Here are the solutions:

1. Disable A Database Error Occurred error prompts in Codeigniter

As mentioned in the CodeIgniter user guide, setting the ENVIRONMENT constant to a value of'development'will allow all PHP error reports to be output to the browser.Conversely, setting the constant'production'will disable the output of all error reports.

Modify error_in index.phpreporting:


define('ENVIRONMENT', 'production'); // Default is development
if (defined('ENVIRONMENT'))  
{  
    switch (ENVIRONMENT)  
    {  
        case 'development':  
            error_reporting(E_ALL);  
        break;  

        case 'testing':  
        case 'production':  
            error_reporting(0);  
        break;  

        default:  
            exit('The application environment is not set correctly.');  
    }  
} 

2. Prohibit A PHP Error was encountered error prompts in Codeigniter

Modify database settings in config/database.php:


$db['default']['db_debug'] = FALSE; 


Related articles: