Exception Handling In Database Connection

Hello every one,

Is there any way that i can redirect to some page on database connection error. I am trying to do this error handling since 2 days but i did not get success.

In my config file following code is specified.

‘errorHandler’=>array(

// use 'site/error' action to display errors


'errorAction'=>'site/error',

),

‘db’=>array(

'connectionString' => 'mysql:host=127.0.0.1;dbname=test',


'emulatePrepare' => true,


'username' => 'root',


'password' => '123',


'charset' => 'utf8',

),

But on database connection error this "actionError" is not called.

Please guide me.

in your site controller just put the action




 public function actionError() {

        if ($error = Yii::app()->errorHandler->error) {

            if (Yii::app()->request->isAjaxRequest)

                echo $error['message'];

            else

                $this->render('error', $error);

        }

    }

Thanks Maggie Q for the quick reply,

This function is already available in my SiteController. I was checking the access_log but i don’t see any entry for the site/error in there. So may be this function is not being called somehow.

Specific error i am getting is as followed.

CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2013] Lost connection to MySQL server at ‘reading initial communication packet’, system error: 111

Thanks in advance.

Try the solution at

http://www.yiiframework.com/forum/index.php/topic/38281-solved-cdbexception-not-being-rendered-in-view/

Errors are handled differently in production mode. The Yii tutorial has more info on this.

check this wiki

also check your DB like


 /*'db'=>array(

            'connectionString' => 'sqlite:protected/data/blog.db',

            'tablePrefix' => 'tbl_',

        ),*/

        // uncomment the following to use a MySQL database

      

        'db'=>array(

            'connectionString' => 'mysql:host=localhost;dbname=vqs',

            'emulatePrepare' => true,

            'username' => 'root',

            'password' => '',

            'charset' => 'utf8',

            'tablePrefix' => 'tbl_',

        ),

Thanks a lot BlkRaven…

You made my day…:)