$txn = Yii::app()->db->beginTransaction();
try
{
$sql = "SELECT ratingID FROM CommentRating cr WHERE cr.commentID=:cID";
$cmd = Yii::app()->db->createCommand($sql);
$cmd->bindValue(':cID', $comment->commentID, PDO::PARAM_INT);
$ids = $cmd->queryColumn();
Yii::app()->db->createCommand('DELETE FROM CommentRating WHERE commentID='.$comment->commentID)->execute();
Yii::app()->db->createCommand('DELETE FROM ProductComment WHERE commentID='.$comment->commentID)->execute();
Yii::app()->db->createCommand('DELETE FROM LookComment WHERE commentID='.$comment->commentID)->execute();
Yii::app()->db->createCommand('DELETE FROM Rating WHERE ratingID IN('.implode(',',$ids).')')->execute();
$comment->delete();
}
catch (CException $e)
{
$txn->rollBack();
}
But it doesn't work! I guess, because when using transaction it doesn't actually remove rows and so when I delete Rating or Comment records, it fails with constraint check.
When I remove transaction handling, it works OK.
When I was using MSSQL, such things worked fine. Is it MySQL’s bugs or Yii’s or mine?