How to handle DB connection errors |
I've just had a quick read through the CodeIgniter source code that triggers the error message you're running into.
In the config/database.php file there is the following setting: Code: $db['default'] = array( and in system/database/DB_driver.php the following code seems to be triggering the error message you're seeing: Code: public function initialize() After a quick test setting db_debug to FALSE in the database.php config does prevent CodeIgniter from hijacking the request to display the error message, and execution will continue, the initialize method should return FALSE if the connection fails. Try changing the following code in your application: Code: $config['db_debug'] = (ENVIRONMENT !== 'production'); to: Code: $config['db_debug'] = FALSE; and check the value that's returned by: Code: $this->load->database($config, TRUE); in your test case, this may help you to detect a failed connection attempt without the error message hijacking the request. I am testing this on the latest version of CodeIgniter (currently v3.1.4), if you are running an older version this may or may not work for you. |
Messages In This Thread |
How to handle DB connection errors - by guilhermemuller - 05-15-2017, 11:42 AM
RE: How to handle DB connection errors - by InsiteFX - 05-15-2017, 01:03 PM
RE: How to handle DB connection errors - by guilhermemuller - 05-16-2017, 06:04 PM
RE: How to handle DB connection errors - by guilhermemuller - 05-18-2017, 07:28 AM
RE: How to handle DB connection errors - by InsiteFX - 05-18-2017, 08:34 AM
RE: How to handle DB connection errors - by reactionstudio - 05-22-2017, 04:33 AM
|