Welcome Guest, Not a member yet? Register   Sign In
SOLVED: graceful error handling of failed external database access
#1

[eluser]blzabub[/eluser]
I've developed a website which accesses 2 separate MySQL databases, one locally on the same server as the web host and another on a remote host. I autoload the database library with both databases configured. This usually works fine, but occasionally, the external database is not available and it causes any site controller that uses that external database to fail and so I get many blank pages. What is the best way to prevent this from happening given the assumption that I cannot control the uptime of the external MySQL server? Is there a way I can change the code that loads the model which uses the external database so that if it fails to connect, it will degrade more elegantly than a blank page. Current code looks like this-

Code:
$this->load->model('calendars_model','',TRUE));

Is this failing at the autoload of the database library level, at the loading of the model level or at the active record query level or at the controller level? I'm afraid my understanding of CI is not deep enough to know.

Thanks for any help,

~Ben
#2

[eluser]blzabub[/eluser]
To anyone having this problem out there, I was able to solve it thusly:
Code:
if ($this->load->model('calendars_model','',TRUE)) {
            $data['cal_events']=$this->calendars_model->retrieve_next_events();
        }

And elsewhere in various views, we check to see if $cal_events is empty or not before trying to display its contents.




Theme © iAndrew 2016 - Forum software by © MyBB