Database Credentials

Hii Everyone!!!

        When I am giving wrong Database credentials like DBname or password at that time YII throws an exception.(attached in post). I want to display proper error message. Please help me for this. Eagerly waiting for your reply. Please be quick as possible.Attachment 4661 not found.

in your config/main.php




'onBeginRequest' => function ($event) {

  try {

    Yii::app()->db->setActive(true);

  } catch (CDbException $ex) {

    var_dump($ex->getMessage()); exit;

  }

},



Thanks for your reply!!

Can you please guide me that exact at which location this code should be written??

After DB Connection or before DB Connection in /config/main.php file…

I have written same code that you have given but it is not working, still giving same error. Is there any change required in your given code?? I put your code after DB Connection.

with config/main.php you are configuring your application object, cwebapplication, you can set all writeable properties as well as event-methods. event-Methods begin with ‘on’ like onBeginRequest. In Yii it is possible to attach event handlers by assigning an anoynmous function.

http://www.yiiframework.com/doc/api/1.1/CApplication/

http://www.yiiframework.com/doc/guide/1.1/en/basics.component#component-event





'import' = array(

...

),


'onBeginRequest' => function ($event) {

  try {

    Yii::app()->db->setActive(true);

  } catch (CDbException $ex) {

    var_dump($ex->getMessage()); exit;

  }

},


'components' => array(

...

)



Thanks…

It is giving an error properly when DB credentials are wrong but then it will not allow to open any page. I want to redirect it to the Login page after displaying this error.