Welcome Guest, Not a member yet? Register   Sign In
[solved] How to detect database connection error?
#1

[eluser]Treeda[/eluser]
Hi there,

simple thing, just modify your password in database config
set debug to false (well on a production site i never ever want user to see errors, sepcial not SQL related errors, so dbdebug has to be false) and call

$this->load->database();

you don't get any error, except you start to do queries .-/

It's not returning anything and it's not firing an exception.

So just to make a site bulletproof and give the user a nice and nifty error message if the database goes down or whatever, how can i detect that?

I aprpeciate any help
Treeda
#2

[eluser]Treeda[/eluser]
SOLVED :-)

sorry i was a bit too quick posting, i just found the solution myself.


for anyone who's interested in doing the same, just do at the very first beginning, your base controller or any other fitting entry point the following.

if the connection id (conn_id) is set, you've got a working database if not then... not

Code:
if ( $this->load->database('', true)->conn_id == false)
            print "error";
        else
            print "success";




Theme © iAndrew 2016 - Forum software by © MyBB