Another solution would be to update your error controller to test the
exception to see if it is a Zend_Db_Adapter_Exception. When the connection
can't be made, this exception is thrown, but there may be other times when
it is thrown (like a bad query).

The advantage, however, is that your DB connection will remain lazy-loaded,
so if you're using caching there may be times when you don't need to connect
to the DB at all.

--
Hector


On Tue, Jan 12, 2010 at 10:31 AM, Jurian Sluiman <subscr...@juriansluiman.nl
> wrote:

> I have this piece of code for my custom db resource, extending the zend db
> resource:
>
> > $db = parent::init();
> > try {
> >     $this->_connection = $db->getConnection();
> > } catch (Exception $e) {
> >     $this->getBootstrap()->bootstrap('log');
> >     Zend_Registry::get('log')->crit('Database connection not
> responding');
> > }
> > return $db;
>
> Now you're using the zend db resource functionality and test for a valid db
> connection. The log (already registered in the registry) is used to
> generate
> some output.
> Regards, Jurian
>
> --
> Jurian Sluiman
> CTO Soflomo V.O.F.
> http://soflomo.com
>
> On Tuesday 12 Jan 2010 19:22:39 scs wrote:
> > Hello,
> > How can I catch the exception and print an error message to visitiors
> > when there is a database connection error?
> > DB connection params are defined in the application.ini. and db
> > resource is initiated in bootstrap file.
> >
> > something like this? :
> >
> > //function initDatabase () {
> > try {
> >       $this->bootstrap('db');
> >       $db = $this->getResource('db');
> >       Zend_Registry::set('db', $db);
> >
> > } catch (Exception $e) {
> >       echo 'db error '.$e->getMessage();
> >       exit; // I have to put exit here in order to prevent other init
> > functions running?
> > }
> >
> > Also,
> > I have to put exit(); in catch part in order to prevent the following
> > init functions run. Is this the correct way?
> >
> > Thanks
> > scs
>

Reply via email to