3One
(Frooble Doo)
1
Hey guys
I have a form with several models attached,
after submission i want to save the records,
but only if all records were inserted successfully.
$trans1 = $model1->dbConnection->beginTransaction();
$trans2 = $model2->dbConnection->beginTransaction();
doesent seem to work, i also tried if i can do this over
all model records:
$modelTrans = CActiveRecord::$db->beginTransaction();
$model->save();
$modelTrans->rollback();
this somehow also doesnt seem to work since the record is being
inserted even though i made a rolback.
Help is much appreciated.
Cheers,
3One
softark
(Softark)
2
I’m doing it this way:
$transaction = Yii::app()->db->beginTransaction();
try
{
$model->save();
$model2->save();
$model3->save();
$transaction->commit();
$this->redirect(array('view','id'=>$model->id));
}
catch (Exception $e)
{
$transaction->rollBack();
Yii::app()->user->setFlash('error', "{$e->getMessage()}");
$this->refresh();
}
Seems to work fine.
3One
(Frooble Doo)
3
i really don’t know what i am doing wrong here,
to test the rollback i added the following:
$transaction = Yii::app()->db->beginTransaction();
$u->save(false);
$transaction->rollback();
but the record is still entered in the database
i dont know what i am doing wrong, i set autocommit
to false in the config file (main.php)
3One
(Frooble Doo)
4
I figured it out, my database is in MyISAM which has no transaction
support, sorry for the inconvenience.
Somehow Yii doesnt throw an error or a warning so i didn’t notice.