What is the rationale (raison d'être) behind CDBTransaction?

Your question is too general…

As I can see, it's just a wrapper of commit and rollback which can fit perfectly in CDBConnection.

That's right. That's why we say Yii DAO is a very thin layer on top of PDO.

Suppose that you have your reason to maintain CDBTransaction in your design as it is.

Don't you think beginTransaction() is the responsibility of CDBTransaction? and

it seems more natural to do something like:

$transaction = new CDBTransaction($connection); // new or create a CDBTransaction




In this case, one can create one more type of Exception(e.g. CDBInactiveTransactionException) that can be thrown in:




such that we can write something like this:


$transaction = new CDBTransaction($connection); // new or create a CDBTransaction








catch(others exceptions){



I agree that your approach gives more flexibility. The main advantage of the current beginTransaction() method is to reduce one line of code (similar to Yii::createWebApplication()). In fact, it is fully possible to implement your approach without modifying existing CDbConnection code.