CodeIgniter Forums

Full Version: CodeIgniter 2.x and shutdown database
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have some database connections, and i load database in controller if necessary.
And i want continue my script work, if database is shutdown.
But if some database is shutdown, my script stopped with error: "unable connect to database".
And i'm solve this problem (db_gebug = FALSE), and now my script also stopped and i see error "undefined variable DB2" from model file, this tell me about CodeIgniter db connection not returning FALSE in my var.

My script logic in controller:
> .......
> $DB2 = $this->load->database('db2', TRUE, TRUE);
> if ($DB2) {
> $this->load->model('some_model');
> //actions
> }
> else $data['content'] = 'server now is shutdown';
> .......

Result: var DB2 not gain FALSE, if mysql server is shutdown, and my script logic not work, and i have errors. And if i change "if ($DB2)" to "if (isset($DB2))", it also not work.
How i can fix it?
Try to check the connection by this way:

PHP Code:
if(false === $DB2->conn_id)
{
   echo 
'No connection';

I alredy understand what the problem is when looked in print_r($DB2), and i use "if ($DB2->conn_id)".