CodeIgniter: how to find out, $ this-> load-> database (); connected?

If I configure my CI application to use a database to handle the session, if the user identifier session returns false, I can assume that the user session has expired.

But what if the actual reason he returned false was because the database connection was not successfully established?

+2
source share
3 answers

By default, CodeIgniter will be a fatal error if the database is loaded and cannot connect, but if you have:

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

then he will not tell you. You can turn off debugging altogether, but still respond to a failed load by doing this:

if ( $this->load->database() === FALSE )
{
   exit('THE END IS NIGH!');
}
+5
source

, , wokrs, , , - dbutil, .

$this->load->database();
$this->load->dbutil();

// check connection details
if( !$this->dbutil->database_exists('myDatabase'))
    echo 'Not connected to a database, or database not exists';
+1

CI throws

A Database Error Occurred
Unable to connect to your database server using the provided settings.

or something like that if the connection fails

0
source

All Articles