function FetchLegacyTest::testQueryFetchColumnOutOfRange

Confirms that an out of range index throws an error.

Attributes

#[IgnoreDeprecations]

File

core/tests/Drupal/KernelTests/Core/Database/FetchLegacyTest.php, line 137

Class

FetchLegacyTest
Tests the Database system's various fetch capabilities.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testQueryFetchColumnOutOfRange() : void {
  $this->expectException(\ValueError::class);
  $this->expectExceptionMessage('Invalid column index');
  $statement = $this->connection
    ->query('SELECT [name] FROM {test} WHERE [age] = :age', [
    ':age' => 25,
  ]);
  $statement->setFetchMode(\PDO::FETCH_COLUMN, 200);
  $statement->fetch();
}

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