$db = \Config\Database::connect();
/* If an established connection is available, then there's
* no need to connect and select the database.
*
* Depending on the database driver, conn_id can be either
* boolean TRUE, a resource or an object.
*/
if ($db->initialize()){
// we have a connection
} else {
// NO Connections
}
// or try
if ($db->connID){
This is because CodeIgnioters database connection does not connect until a query is ran.