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