function FetchTest::testQueryFetchBoth
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/FetchTest.php \Drupal\KernelTests\Core\Database\FetchTest::testQueryFetchBoth()
- 10 core/tests/Drupal/KernelTests/Core/Database/FetchTest.php \Drupal\KernelTests\Core\Database\FetchTest::testQueryFetchBoth()
Confirms that we can fetch a record into a doubly-keyed array explicitly.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ FetchTest.php, line 138
Class
- FetchTest
- Tests the Database system's various fetch capabilities.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testQueryFetchBoth() {
$records = [];
$result = $this->connection
->query('SELECT name FROM {test} WHERE age = :age', [
':age' => 25,
], [
'fetch' => \PDO::FETCH_BOTH,
]);
foreach ($result as $record) {
$records[] = $record;
$this->assertIsArray($record);
$this->assertArrayHasKey(0, $record);
$this->assertSame('John', $record[0]);
$this->assertArrayHasKey('name', $record);
$this->assertSame('John', $record['name']);
}
$this->assertCount(1, $records, 'There is only one record.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.