Db Transations

Hi All,

I have one doubt about the transactions. When I have this piece of code, the connection of the model uses the same transaction? All commands are executed inside of the same connection?



$transaction = Yii::app()->db->beginTransaction();

$item = Item::model()->findByPk(‘1’);

$item->Name = Xpto;


   throw new CDbException('Errorrrr');

$sql = ‘INSERT INTO ItemHistoric (ItemId, Stock) SELECT ItemId, Stock FROM Item WHERE 1 = 1’;

$command = Yii::app()->db->createCommand($sql);

$rowCount = $command->execute();



catch (Exception $e) {



ps: Please note this just very, very dummy sample. It’s just to exemplify.


Well, yes. All commands will be executed on the same connection within the same transaction.