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 DatabaseFetchTestCase::testQueryFetchDefault

Confirm that we can fetch a record properly in default object mode.

File

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

Class

DatabaseFetchTestCase
Test fetch actions, part 1.

Code

function testQueryFetchDefault() {
 $records = array();
 $result = db_query ('SELECT name FROM {test} WHERE age = :age', array(
 ':age' => 25,
 ));
 $this->assertTrue ($result instanceof DatabaseStatementInterface, 'Result set is a Drupal statement object.');
 foreach ($result as $record) {
 $records[] = $record;
 $this->assertTrue (is_object ($record), 'Record is an object.');
 $this->assertIdentical ($record->name , 'John', '25 year old is John.');
 }
 $this->assertIdentical (count ($records), 1, 'There is only one record.');
}

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