Hi -
I need to capture db error thrown by CActiveRecord::save() function. Actually there is a foreign key constraint in my DB, so whenever I’m trying to insert any value which is not existing in the reference table than CDB throwing an error, but I can’t capture that. Below is my code:
$objReviewFacility=new ReviewParametersFacility();
$objReviewFacility->review_parameter_id=$paramId;
$objReviewFacility->facility_id=$facility;
try {
$objReviewFacility->save();
unset($objReviewFacility);
}
catch(Exception $e) {
throw new CHttpException($e->getCode(),$e->getMessage());
}
I’m getting below error, but this error is not thrown by my “Catch” statement, actually my “catch” is not being executed at all.
CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 1452 Cannot add or update a child row: a foreign key constraint fails (`review_parameters_facility`, CONSTRAINT `review_parameter_facility_facility_id` FOREIGN KEY (`facility_id`) REFERENCES `facilities` (`id`)). The SQL statement executed was: INSERT INTO `review_parameters_facility` (`review_parameter_id`, `facility_id`) VALUES (:yp0, :yp1)