Error message

You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).

function DatabaseFetch2TestCase::testQueryFetchCol

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

File

modules/simpletest/tests/database_test.test, line 528

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.