Cake\Database\Connection::commit PHP Method

commit() public method

Commits current transaction.
public commit ( ) : boolean
return boolean true on success, false otherwise
    public function commit()
    {
        if (!$this->_transactionStarted) {
            return false;
        }
        if ($this->_transactionLevel === 0) {
            $this->_transactionStarted = false;
            if ($this->_logQueries) {
                $this->log('COMMIT');
            }
            return $this->_driver->commitTransaction();
        }
        if ($this->useSavePoints()) {
            $this->releaseSavePoint($this->_transactionLevel);
        }
        $this->_transactionLevel--;
        return true;
    }

Usage Example

 /**
  * @param object $command
  * @param callable $next
  *
  * @return mixed
  * @throws \Exception when Transaction fails to commit.
  */
 public function execute($command, callable $next)
 {
     $this->connection->begin();
     try {
         $returnValue = $next($command);
         $isCommitted = $this->connection->commit();
     } catch (\Exception $e) {
         $this->connection->rollback();
         throw $e;
     }
     if (!$isCommitted) {
         throw new \Exception('Failed to commit the transaction.');
     }
     return $returnValue;
 }
All Usage Examples Of Cake\Database\Connection::commit