1 database_test.test DatabaseFetch2TestCase::testQueryFetchCol()

Confirm that we can fetch an entire column of a result set at once.

File

core/modules/simpletest/tests/database_test.test, line 458
Database tests.

Class

DatabaseFetch2TestCase
Test fetch actions, part 2.

Code

function testQueryFetchCol() {
  $records = array();
  $result = db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25));
  $column = $result->fetchCol();
  $this->assertIdentical(count($column), 3, 'fetchCol() returns the right number of records.');

  $result = db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25));
  $i = 0;
  foreach ($result as $record) {
    $this->assertIdentical($record->name, $column[$i++], 'Column matches direct accesss.');
  }
}