DboSource::begin PHP Method

begin() public method

Begin a transaction
public begin ( ) : 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 begin()
    {
        if ($this->_transactionStarted) {
            if ($this->nestedTransactionSupported()) {
                return $this->_beginNested();
            }
            $this->_transactionNesting++;
            return $this->_transactionStarted;
        }
        $this->_transactionNesting = 0;
        if ($this->fullDebug) {
            $this->logQuery('BEGIN');
        }
        return $this->_transactionStarted = $this->_connection->beginTransaction();
    }

Usage Example

Exemplo n.º 1
0
 /**
  * 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::begin
DboSource