function Connection::prepareStatement
Same name in this branch
- 11.x core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::prepareStatement()
- 11.x core/modules/pgsql/src/Driver/Database/pgsql/Connection.php \Drupal\pgsql\Driver\Database\pgsql\Connection::prepareStatement()
Same name in other branches
- 9 core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::prepareStatement()
- 9 core/modules/pgsql/src/Driver/Database/pgsql/Connection.php \Drupal\pgsql\Driver\Database\pgsql\Connection::prepareStatement()
- 9 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::prepareStatement()
- 10 core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::prepareStatement()
- 10 core/modules/pgsql/src/Driver/Database/pgsql/Connection.php \Drupal\pgsql\Driver\Database\pgsql\Connection::prepareStatement()
- 10 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::prepareStatement()
Returns a prepared statement given a SQL string.
This method caches prepared statements, reusing them when possible. It also prefixes tables names enclosed in curly braces and, optionally, quotes identifiers enclosed in square brackets.
Parameters
string $query: The query string as SQL, with curly braces surrounding the table names, and square brackets surrounding identifiers.
array $options: An associative array of options to control how the query is run. See the documentation for self::defaultOptions() for details. The content of the 'pdo' key will be passed to the prepared statement.
bool $allow_row_count: (optional) A flag indicating if row count is allowed on the statement object. Defaults to FALSE.
Return value
\Drupal\Core\Database\StatementInterface A prepared statement ready for its execute() method.
Throws
\InvalidArgumentException If multiple statements are included in the string, and delimiters are not allowed in the query.
\Drupal\Core\Database\DatabaseExceptionWrapper
2 calls to Connection::prepareStatement()
- Connection::prepareStatement in core/
modules/ pgsql/ src/ Driver/ Database/ pgsql/ Connection.php - Connection::query in core/
lib/ Drupal/ Core/ Database/ Connection.php - Executes a query string against the database.
2 methods override Connection::prepareStatement()
- Connection::prepareStatement in core/
modules/ sqlite/ src/ Driver/ Database/ sqlite/ Connection.php - Connection::prepareStatement in core/
modules/ pgsql/ src/ Driver/ Database/ pgsql/ Connection.php
File
-
core/
lib/ Drupal/ Core/ Database/ Connection.php, line 431
Class
- Connection
- Base Database API class.
Namespace
Drupal\Core\DatabaseCode
public function prepareStatement(string $query, array $options, bool $allow_row_count = FALSE) : StatementInterface {
assert(!isset($options['return']), 'Passing "return" option to prepareStatement() has no effect. See https://www.drupal.org/node/3185520');
try {
$query = $this->preprocessStatement($query, $options);
$statement = new $this->statementWrapperClass($this, $this->connection, $query, $options['pdo'] ?? [], $allow_row_count);
} catch (\Exception $e) {
$this->exceptionHandler()
->handleStatementException($e, $query, $options);
}
return $statement;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.