SoFunction
Updated on 2025-03-10

Methods to prohibit A Database Error Occurred error prompts in Codeigniter

By default, CodeIgniter displays all PHP errors. But when you develop the program, you may want to change this situation.
You will find that there is this function error_reporting() at the top of the file, through which you can set the error. Even if you close the error report, the error logging will not stop when an error occurs.
Therefore, modification cannot achieve the effect we want.

Here is the solution:

1. A Database Error Occurred error prompt is prohibited in Codeigniter

In the CodeIgniter User Guide, setting the ENVIRONMENT constant to the 'development' value will allow all PHP error reports to be output to the browser. Conversely, setting the constant to 'production' will disable all outputs of error reports.

Modify error_reporting:

Copy the codeThe code is as follows:

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. A PHP Error was prevented in Codeigniter.

Modify database settings in config/:

Copy the codeThe code is as follows:

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