* The query to execute. In most cases this will be a string containing
* an SQL query with placeholders. An already-prepared instance of
* StatementInterface may also be passed in order to allow calling
* code to manually bind variables to a query. If a
* StatementInterface is passed, the $args array will be ignored.
* The query to execute. This is a string containing an SQL query with
* placeholders.
* (deprecated) An already-prepared instance of StatementInterface or of
* \PDOStatement may also be passed in order to allow calling code to
* manually bind variables to a query. In such cases, the content of the
* $args array will be ignored.
* It is extremely rare that module code will need to pass a statement
* object to this method. It is used primarily for database drivers for
* databases that require special LOB field handling.
@@ -792,14 +793,16 @@ public function query($query, array $args = [], $options = []) {
assert(!isset($options['target']),'Passing "target" option to query() has no effect. See https://www.drupal.org/node/2993033');
try{
// We allow either a pre-bound statement object or a literal string.
// In either case, we want to end up with an executed statement object,
// which we pass to PDOStatement::execute.
// We allow either a pre-bound statement object (deprecated) or a literal
// string. In either case, we want to end up with an executed statement
// object, which we pass to PDOStatement::execute.
if($queryinstanceofStatementInterface){
@trigger_error('Passing a StatementInterface object as a $query argument to '.__METHOD__.' is deprecated in drupal:9.2.0 and is removed in drupal:10.0.0. Call the execute method from the StatementInterface object directly instead. See https://www.drupal.org/node/3154439',E_USER_DEPRECATED);
$stmt=$query;
$stmt->execute(NULL,$options);
}
elseif($queryinstanceof\PDOStatement){
@trigger_error('Passing a \\PDOStatement object as a $query argument to '.__METHOD__.' is deprecated in drupal:9.2.0 and is removed in drupal:10.0.0. Call the execute method from the StatementInterface object directly instead. See https://www.drupal.org/node/3154439',E_USER_DEPRECATED);
$this->expectDeprecation('Passing a StatementInterface object as a $query argument to Drupal\Core\Database\Connection::query is deprecated in drupal:9.2.0 and is removed in drupal:10.0.0. Call the execute method from the StatementInterface object directly instead. See https://www.drupal.org/node/3154439');
$db=Database::getConnection();
$stmt=$db->prepareStatement('SELECT * FROM {test}',[]);
$this->assertNotNull($db->query($stmt));
}
/**
* Tests the deprecation of passing a PDOStatement object to ::query.
$this->markTestSkipped("This test only runs for PDO-based db drivers.");
}
$this->expectDeprecation('Passing a \\PDOStatement object as a $query argument to Drupal\Core\Database\Connection::query is deprecated in drupal:9.2.0 and is removed in drupal:10.0.0. Call the execute method from the StatementInterface object directly instead. See https://www.drupal.org/node/3154439');