DboSource::lastAffected PHP Method

lastAffected() public method

Returns number of affected rows in previous database operation. If no previous operation exists, this returns false.
public lastAffected ( mixed $source = null ) : integer
$source mixed The source to check.
return integer Number of affected rows
    public function lastAffected($source = null)
    {
        if ($this->hasResult()) {
            return $this->_result->rowCount();
        }
        return 0;
    }

Usage Example

 /**
  * testLastAffected method
  *
  *
  * @return void
  */
 public function testLastAffected()
 {
     $this->Dbo->cacheSources = false;
     $tableName = 'tinyint_' . uniqid();
     $this->Dbo->rawQuery('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
     $this->model = new CakeTestModel(array('name' => 'Tinyint', 'table' => $tableName, 'ds' => 'test'));
     $this->assertTrue((bool) $this->model->save(array('bool' => 5, 'small_int' => 5)));
     $this->assertEquals(1, $this->model->find('count'));
     $this->model->deleteAll(true);
     $result = $this->Dbo->lastAffected();
     $this->assertEquals(1, $result);
     $this->assertEquals(0, $this->model->find('count'));
     $this->Dbo->rawQuery('DROP TABLE ' . $this->Dbo->fullTableName($tableName));
 }
All Usage Examples Of DboSource::lastAffected
DboSource