[SOLVED] CDbException

Hello,

I have a problem with de CDbException. In my DB I have a UNIQUE filder, but when (in m application) I create a new cliente with the same UNIQUE filder registred show me an error like this:

CDbCommand falhou ao executar o comando SQL: SQLSTATE …

I solved this problem with the rules at my model cliente, but I want if I forget handling this to show in user’s view the helpfull form, and after show to the user, I want to send to me an email solving this problem.

For CHttpException has errorhandler; has any to CDbException?

Thank you,

Giovanna

[sorry my english]

CDbCommand falhou ao executar o comando SQL: SQLSTATE …

please can you tell me in english what it means

alirs23,

This is an CDbException. In my case, its mean I create a new client with the same CPF (UNIQUE filder) registred in DB.

In my rules at DB it cannot occur, then the application show me this error, but I do not want this error to be shown to the user.

you can hide when you deploy change your index file


defined('YII_DEBUG') or define('YII_DEBUG',true); // comment it out

alirz23,

Thank you very much! It solved my problem.

=)

you welcome

How about adding validation rule for that particular unique field. For example:




public function rules()

{   

   return array(      

      ..............................

      array('user_id', 'unique'),

      ..............................      

   );

}



Then Yii won’t complain or put any CDbException errors under your application.log. Instead it will present user with friendly error message like below:




User Id "yii" has already been taken.



Yohan Hirimuthugoda,

I wanted that because I need an email is sent to me if anything wrong about DB occur.

// Giovanna