You are here

function FetchTest::testQueryFetchCol in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Database/FetchTest.php \Drupal\system\Tests\Database\FetchTest::testQueryFetchCol()

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

File

core/modules/system/src/Tests/Database/FetchTest.php, line 123
Contains \Drupal\system\Tests\Database\FetchTest.

Class

FetchTest
Tests the Database system's various fetch capabilities.

Namespace

Drupal\system\Tests\Database

Code

function testQueryFetchCol() {
  $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 access.');
  }
}