Yii2 Transaction

The following code is a typical example of using transactions (note that some DBMS may not support transactions):

$transaction = $connection->beginTransaction();
try {
    $connection->createCommand($sql1)->execute();
    $connection->createCommand($sql2)->execute();
    //.... other SQL executions
    $transaction->commit();
} catch (\Exception $e) {
    $transaction->rollBack();
    throw $e;
}

 

Add a Comment

Your email address will not be published. Required fields are marked *