Skip to content

Instantly share code, notes, and snippets.

@yemaw
Created March 9, 2015 09:55
Show Gist options
  • Save yemaw/8e9ff7962557fb8a4b64 to your computer and use it in GitHub Desktop.
Save yemaw/8e9ff7962557fb8a4b64 to your computer and use it in GitHub Desktop.
Yii (1) transaction, rollback and commit .
$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