Cdbconnection - Check If Connection Is Successful

Hi all,

I have to connect to second DB but in just one page. So I do it with local CDbConnection like this




$connection=new CDbConnection($dsn,$username,$password);

$connection->active=true;



And it’s ok but if DB server is down there is an error and other data on that page is lost (only error is displaying). Is there a way first to check if CDbConnection is successful and if is not just render other data.

Thanks.


try

{

  $connection=new CDbConnection($dsn,$username,$password);

  $connection->active=true;

}

catch(CDbException $e)

{

  echo $e->getMessage(); // Or do something else

}