function FetchLegacyTest::testQueryFetchAllColumn
Confirms that we can fetch all records into an array explicitly.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ FetchLegacyTest.php, line 80
Class
- FetchLegacyTest
- Tests the Database system's various fetch capabilities.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testQueryFetchAllColumn() : void {
$this->expectDeprecation("Passing the \$mode argument as an integer to fetchAll() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \\Drupal\\Core\\Database\\FetchAs enum instead. See https://www.drupal.org/node/3488338");
$query = $this->connection
->select('test');
$query->addField('test', 'name');
$query->orderBy('name');
$query_result = $query->execute()
->fetchAll(\PDO::FETCH_COLUMN);
$expected_result = [
'George',
'John',
'Paul',
'Ringo',
];
$this->assertEquals($expected_result, $query_result, 'Returned the correct result.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.