function Connection::prepareQuery

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php \Drupal\Core\Database\Driver\sqlite\Connection::prepareQuery()
  2. 8.9.x core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php \Drupal\Core\Database\Driver\pgsql\Connection::prepareQuery()
  3. 8.9.x core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::prepareQuery()

Prepares a query string and returns the prepared statement.

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

$query: The query string as SQL, with curly-braces surrounding the table names.

bool $quote_identifiers: (optional) Quote any identifiers enclosed in square brackets. Defaults to TRUE.

Return value

\Drupal\Core\Database\StatementInterface A PDO prepared statement ready for its execute() method.

Deprecated

in drupal:9.1.0 and is removed from drupal:10.0.0. Use ::prepareStatement instead.

See also

https://www.drupal.org/node/3137786

File

core/lib/Drupal/Core/Database/Connection.php, line 714

Class

Connection
Base Database API class.

Namespace

Drupal\Core\Database

Code

public function prepareQuery($query, $quote_identifiers = TRUE) {
    @trigger_error('Connection::prepareQuery() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use ::prepareStatement() instead. See https://www.drupal.org/node/3137786', E_USER_DEPRECATED);
    return $this->prepareStatement($query, [
        'allow_square_brackets' => !$quote_identifiers,
    ]);
}

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