Doctrine\DBAL\Connection::setAutoCommit PHP Method

setAutoCommit() public method

If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either the method commit or the method rollback. By default, new connections are in auto-commit mode. NOTE: If this method is called during a transaction and the auto-commit mode is changed, the transaction is committed. If this method is called and the auto-commit mode is not changed, the call is a no-op.
See also: isAutoCommit
public setAutoCommit ( boolean $autoCommit )
$autoCommit boolean True to enable auto-commit mode; false to disable it.
    public function setAutoCommit($autoCommit)
    {
        $autoCommit = (bool) $autoCommit;
        // Mode not changed, no-op.
        if ($autoCommit === $this->autoCommit) {
            return;
        }
        $this->autoCommit = $autoCommit;
        // Commit all currently active transactions if any when switching auto-commit mode.
        if (true === $this->_isConnected && 0 !== $this->_transactionNestingLevel) {
            $this->commitAll();
        }
    }

Usage Example

 /**
  * Deletes all nodes with edges from database
  *
  * @throws DatabaseErrorException
  */
 public function delete()
 {
     try {
         $this->dbal->setAutoCommit(false);
         $this->dbal->beginTransaction();
         $this->dbal->executeQuery('DELETE FROM relations');
         $this->dbal->executeQuery('DELETE FROM organizations');
         $this->dbal->commit();
         $this->dbal->setAutoCommit(true);
     } catch (\Doctrine\DBAL\ConnectionException $exception) {
         throw new DatabaseErrorException($exception);
     } catch (\Doctrine\DBAL\DBALException $exception) {
         $this->dbal->rollBack();
         $this->dbal->setAutoCommit(true);
         throw new DatabaseErrorException($exception);
     }
 }
All Usage Examples Of Doctrine\DBAL\Connection::setAutoCommit