Welcome Guest, Not a member yet? Register   Sign In
Check if Database Library is loaded and Connected to Database

What's the best way to check if inside the constructor of a controller to see if the database library is loaded and connected to a database?

The best I could come up with was this
if (isset($this->db->conn_id) && is_resource($this->db->conn_id)) {
     echo 'database is loaded and conected';

Is this the most effective way?

Well... it will fail if you use mysqli driver, where the conn_id is an object...
I think you can check $this->db->conn_id !== FALSE, because false is the default value.

Also, where can I find the CI_DB class?

I see this used a lot.
if (class_exists('CI_DB')) {}

EDIT: nm about this, i found out that it's created in an eval() function just as an empty class that extends main database class.

Theme © iAndrew 2016 - Forum software by © MyBB