Skip to content

Instantly share code, notes, and snippets.

@raihan-uddin
Created September 28, 2022 09:52
Show Gist options
  • Save raihan-uddin/5bb1926ed4feb9d3f60ffa8ae2779ed7 to your computer and use it in GitHub Desktop.
Save raihan-uddin/5bb1926ed4feb9d3f60ffa8ae2779ed7 to your computer and use it in GitHub Desktop.
yii1 transection
$transaction = Yii::app()->db->beginTransaction();
try {
if (!$model->save()) {
throw new Exception('Model cannot be saved.');
}
if (!$anothermodel->save()) {
throw new Exception('Anothermodel cannot be saved.');
}
$transaction->commit();
} catch (Exception $e) {
$transaction->rollback();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment