function FetchLegacyTest::testQueryFetchNum
Confirms that we can fetch a record into an indexed array explicitly.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ FetchLegacyTest.php, line 60
Class
- FetchLegacyTest
- Tests the Database system's various fetch capabilities.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testQueryFetchNum() : void {
$this->expectDeprecation("Passing the 'fetch' key as an integer to \$options in query() 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");
$this->expectDeprecation("Passing the 'fetch' key as an integer to \$options in prepareStatement() 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");
$this->expectDeprecation("Passing the 'fetch' key as an integer to \$options in execute() 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");
$records = [];
$result = $this->connection
->query('SELECT [name] FROM {test} WHERE [age] = :age', [
':age' => 25,
], [
'fetch' => \PDO::FETCH_NUM,
]);
foreach ($result as $record) {
$records[] = $record;
$this->assertIsArray($record);
$this->assertArrayHasKey(0, $record);
$this->assertSame('John', $record[0]);
}
$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.