DboSource::rollback PHP Method

rollback() public method

Rollback a transaction
public rollback ( ) : boolean
return boolean True on success, false on fail (i.e. if the database/model does not support transactions, or a transaction has not started).
    public function rollback()
    {
        if (!$this->_transactionStarted) {
            return false;
        }
        if ($this->_transactionNesting === 0) {
            if ($this->fullDebug) {
                $this->logQuery('ROLLBACK');
            }
            $this->_transactionStarted = false;
            return $this->_connection->rollBack();
        }
        if ($this->nestedTransactionSupported()) {
            return $this->_rollbackNested();
        }
        $this->_transactionNesting--;
        return true;
    }

Usage Example

 /**
  * Test nested transaction
  *
  * @return void
  */
 public function testNestedTransaction()
 {
     $nested = $this->Dbo->useNestedTransactions;
     $this->Dbo->useNestedTransactions = true;
     if ($this->Dbo->nestedTransactionSupported() === false) {
         $this->Dbo->useNestedTransactions = $nested;
         $this->skipIf(true, 'The MySQL server do not support nested transaction');
     }
     $this->loadFixtures('Inno');
     $model = ClassRegistry::init('Inno');
     $model->hasOne = $model->hasMany = $model->belongsTo = $model->hasAndBelongsToMany = array();
     $model->cacheQueries = false;
     $this->Dbo->cacheMethods = false;
     $this->assertTrue($this->Dbo->begin());
     $this->assertNotEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->begin());
     $this->assertTrue($model->delete(1));
     $this->assertEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->rollback());
     $this->assertNotEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->begin());
     $this->assertTrue($model->delete(1));
     $this->assertEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->commit());
     $this->assertEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->rollback());
     $this->assertNotEmpty($model->read(null, 1));
     $this->Dbo->useNestedTransactions = $nested;
 }
All Usage Examples Of DboSource::rollback
DboSource