Cake\Database\Connection::begin PHP Méthode

begin() public méthode

Starts a new transaction.
public begin ( ) : void
Résultat void
    public function begin()
    {
        if (!$this->_transactionStarted) {
            if ($this->_logQueries) {
                $this->log('BEGIN');
            }
            $this->_driver->beginTransaction();
            $this->_transactionLevel = 0;
            $this->_transactionStarted = true;
            return;
        }
        $this->_transactionLevel++;
        if ($this->useSavePoints()) {
            $this->createSavePoint($this->_transactionLevel);
        }
    }

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::begin