Welcome Guest, Not a member yet? Register   Sign In
Database Connection Check
#1

I am connecting multiple database to my software. I need to check the status of the database connection in controller. If the database is connected it should show the message connected and if it is not connected it should redirect me to baseurl or etc.
Thankyou in Advance
Reply
#2

you can do this sort of thing:

$db2 = \Config\Database::connect('custom');
$t= \Config\Database::getConnections();
print_r($t);

output of print_r($t) is:

Code:
Array ( [custom] => CodeIgniter\Database\SQLite3\Connection Object ( [DBDriver] => SQLite3 [escapeChar] => ` [_random_keyword:protected] => Array ( [0] => RANDOM() ) [DSN:protected] => [port:protected] => 3306 [hostname:protected] => localhost [username:protected] => [password:protected] => [database:protected] => /var/www/htdocs/andrinaPerfectBeauty/writable/Art2 [subdriver:protected] => [DBPrefix:protected] => [pConnect:protected] => [DBDebug:protected] => 1 [cacheOn:protected] => [cacheDir:protected] => [charset:protected] => utf8 [DBCollat:protected] => utf8_general_ci [swapPre:protected] => [encrypt:protected] => [compress:protected] => [strictOn:protected] => [failover:protected] => Array ( ) [lastQuery:protected] => [connID] => [resultID] => [protectIdentifiers] => 1 [reservedIdentifiers:protected] => Array ( [0] => * ) [likeEscapeStr] => ESCAPE '%s' [likeEscapeChar] => ! [dataCache] => Array ( ) [connectTime:protected] => [connectDuration:protected] => [pretend:protected] => [transEnabled] => 1 [transStrict] => 1 [transDepth:protected] => 0 [transStatus:protected] => 1 [transFailure:protected] => [aliasedTables:protected] => Array ( ) ) )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB