Welcome Guest, Not a member yet? Register   Sign In
How to Check if database connection exists Ci4
#2

(This post was last modified: 07-14-2021, 02:42 AM by InsiteFX.)

These are not tested but one of them should work for you.

PHP Code:
$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
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: How to Check if database connection exists Ci4 - by InsiteFX - 07-14-2021, 02:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB