yii\db\Transaction::commit PHP Method

commit() public method

Commits a transaction.
public commit ( )
    public function commit()
    {
        if (!$this->getIsActive()) {
            throw new Exception('Failed to commit transaction: transaction was inactive.');
        }
        $this->_level--;
        if ($this->_level === 0) {
            Yii::trace('Commit transaction', __METHOD__);
            $this->db->pdo->commit();
            $this->db->trigger(Connection::EVENT_COMMIT_TRANSACTION);
            return;
        }
        $schema = $this->db->getSchema();
        if ($schema->supportsSavepoint()) {
            Yii::trace('Release savepoint ' . $this->_level, __METHOD__);
            $schema->releaseSavepoint('LEVEL' . $this->_level);
        } else {
            Yii::info('Transaction not committed: nested transaction not supported', __METHOD__);
        }
    }

Usage Example

コード例 #1
0
 /**
  * Commits a DB transaction if valid
  *
  * @param null|Transaction $transaction
  */
 protected static function tranCommit($transaction)
 {
     if ($transaction && $transaction instanceof Transaction) {
         $transaction->commit();
     }
 }
All Usage Examples Of yii\db\Transaction::commit