CodeIgniter Forums
Check if database connection can be established - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: Check if database connection can be established (/showthread.php?tid=64243)



Check if database connection can be established - Seb33300 - 01-30-2016

My application can be used with or without a database so I need to know if a database is correctly configured to show or hide functionalities which require a database.
How can I access to database config vars to check if they are filled?
Everything I found on the web requires to do a 
Code:
$this->load->database();

 so I can access to database vars from the 

Code:
$this->db

 object.

The problem is that if we do not have a database or if the database config file is not properly set, 
Code:
$this->load->database();

 will results in a PHP error:

Quote:Unable to connect to your database server using the provided settings.



RE: Check if database connection can be established - Narf - 01-30-2016

Turn db_debug Off.


RE: Check if database connection can be established - Narf - 01-30-2016

Also, please don't cross-post.


RE: Check if database connection can be established - freddy - 01-31-2016

(01-30-2016, 01:03 PM)Narf Wrote: Also, please don't cross-post.

oh cool you check also in stackoverflow too !


RE: Check if database connection can be established - Narf - 02-01-2016

(01-31-2016, 06:09 PM)freddy Wrote:
(01-30-2016, 01:03 PM)Narf Wrote: Also, please don't cross-post.

oh cool you check also in stackoverflow too !

I don't "check", I just happen to be a SO user as well.