DB Transaction problem - bug ?


I have problem with transaction in loop.

I open transaction In loop and commit data only if all is correct, if no then rollback transaction and continue loop. Here all work ok.

But problem is when I try save AR model after loop. Validation model is correct save method return true but data not save in my database.

There is nothing magic here. Test whether the data you commit inside the transaction has been committed correctly. If it hasn’t, you have a problem with the transaction code. If it does, then you have an error in your AR model code or the controller class somewhere so it is not saving. Perhaps it is saving as a new record and you expect an update? Perhaps the other way round?

Check this example, I think that its correct but I don’t know why data after my loop don’t save in database

        foreach ($rows as $row) {

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


		try {



		} catch (\Exception $e) {         


                    $log = new Log();


                    $log->save(); //correct save data in database




	$TestOb = Test::findOne(1);

        $TestOb->setAttribute('test', 100);


           echo 'valid'; //return valid


           echo 'invalid';


        $status = $TestOb->save(); //model atrribute are correct - but no data in database

        var_dump($status); //return true