Created
March 9, 2015 09:55
-
-
Save yemaw/8e9ff7962557fb8a4b64 to your computer and use it in GitHub Desktop.
Yii (1) transaction, rollback and commit .
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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