function FetchTest::testQueryFetchArray in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/system/src/Tests/Database/FetchTest.php \Drupal\system\Tests\Database\FetchTest::testQueryFetchArray()
Confirms that we can fetch a record to an associative array explicitly.
File
- core/
modules/ system/ src/ Tests/ Database/ FetchTest.php, line 56 - Contains \Drupal\system\Tests\Database\FetchTest.
Class
- FetchTest
- Tests the Database system's various fetch capabilities.
Namespace
Drupal\system\Tests\DatabaseCode
function testQueryFetchArray() {
$records = array();
$result = db_query('SELECT name FROM {test} WHERE age = :age', array(
':age' => 25,
), array(
'fetch' => \PDO::FETCH_ASSOC,
));
foreach ($result as $record) {
$records[] = $record;
if ($this
->assertTrue(is_array($record), 'Record is an array.')) {
$this
->assertIdentical($record['name'], 'John', 'Record can be accessed associatively.');
}
}
$this
->assertIdentical(count($records), 1, 'There is only one record.');
}