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.
 /**
  * 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);
     }
 }
Exemplo n.º 2
0
 /**
  * @group DBAL-81
  */
 public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions()
 {
     $driverMock = $this->getMock('Doctrine\\DBAL\\Driver');
     $driverMock->expects($this->any())->method('connect')->will($this->returnValue(new DriverConnectionMock()));
     $conn = new Connection(array('platform' => new Mocks\MockPlatform()), $driverMock);
     $conn->connect();
     $conn->beginTransaction();
     $conn->beginTransaction();
     $conn->setAutoCommit(false);
     $this->assertSame(1, $conn->getTransactionNestingLevel());
     $conn->beginTransaction();
     $conn->beginTransaction();
     $conn->setAutoCommit(true);
     $this->assertFalse($conn->isTransactionActive());
 }