function QueryTest::testArraySubstitution
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/QueryTest.php \Drupal\KernelTests\Core\Database\QueryTest::testArraySubstitution()
- 8.9.x core/tests/Drupal/KernelTests/Core/Database/QueryTest.php \Drupal\KernelTests\Core\Database\QueryTest::testArraySubstitution()
- 10 core/tests/Drupal/KernelTests/Core/Database/QueryTest.php \Drupal\KernelTests\Core\Database\QueryTest::testArraySubstitution()
Tests that we can pass an array of values directly in the query.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ QueryTest.php, line 20
Class
- QueryTest
- Tests Drupal's extended prepared statement syntax.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testArraySubstitution() : void {
$names = $this->connection
->query('SELECT [name] FROM {test} WHERE [age] IN ( :ages[] ) ORDER BY [age]', [
':ages[]' => [
25,
26,
27,
],
])
->fetchAll();
$this->assertCount(3, $names, 'Correct number of names returned');
$names = $this->connection
->query('SELECT [name] FROM {test} WHERE [age] IN ( :ages[] ) ORDER BY [age]', [
':ages[]' => [
25,
],
])
->fetchAll();
$this->assertCount(1, $names, 'Correct number of names returned');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.