function DatabaseFetch2TestCase::testQueryFetchCol in Drupal 7
Confirm that we can fetch an entire column of a result set at once.
File
- modules/
simpletest/ tests/ database_test.test, line 464
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.');
}
}