function FetchTest::testQueryFetchCol

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

File

drupal/core/modules/system/lib/Drupal/system/Tests/Database/FetchTest.php, line 129
Definition of Drupal\system\Tests\Database\FetchTest.

Class

FetchTest
Tests fetch actions.

Namespace

Drupal\system\Tests\Database

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.');
  }
}