function Connection::prepare

Same name in this branch
  1. 9 core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::prepare()
Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php \Drupal\Core\Database\Driver\sqlite\Connection::prepare()
  2. 8.9.x core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::prepare()

Prepares a statement for execution and returns a statement object.

Emulated prepared statements do not communicate with the database server so this method does not check the statement.

Parameters

string $statement: This must be a valid SQL statement for the target database server.

array $driver_options: (optional) This array holds one or more key=>value pairs to set attribute values for the PDOStatement object that this method returns. You would most commonly use this to set the \PDO::ATTR_CURSOR value to \PDO::CURSOR_SCROLL to request a scrollable cursor. Some drivers have driver specific options that may be set at prepare-time. Defaults to an empty array.

Return value

\PDOStatement|false If the database server successfully prepares the statement, returns a \PDOStatement object. If the database server cannot successfully prepare the statement returns FALSE or emits \PDOException (depending on error handling).

Throws

\PDOException

Deprecated

in drupal:9.1.0 and is removed from drupal:10.0.0. Database drivers should instantiate \PDOStatement objects by calling \PDO::prepare in their Connection::prepareStatement method instead. \PDO::prepare should not be called outside of driver code.

See also

https://www.php.net/manual/en/pdo.prepare.php

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

1 method overrides Connection::prepare()
Connection::prepare in core/modules/sqlite/src/Driver/Database/sqlite/Connection.php
Prepares a statement for execution and returns a statement object.

File

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

Class

Connection
Base Database API class.

Namespace

Drupal\Core\Database

Code

public function prepare($statement, array $driver_options = []) {
    @trigger_error('Connection::prepare() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Database drivers should instantiate \\PDOStatement objects by calling \\PDO::prepare in their Connection::prepareStatement method instead. \\PDO::prepare should not be called outside of driver code. See https://www.drupal.org/node/3137786', E_USER_DEPRECATED);
    return $this->statementWrapperClass ? (new $this->statementWrapperClass($this, $this->connection, $statement, $driver_options))
        ->getClientStatement() : $this->connection
        ->prepare($statement, $driver_options);
}

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