Statement.php in Drupal 9
File
core/lib/Drupal/Core/Database/Statement.php
View source
<?php
namespace Drupal\Core\Database;
@trigger_error('\\Drupal\\Core\\Database\\Statement is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Database drivers should use or extend StatementWrapper instead, and encapsulate client-level statement objects. See https://www.drupal.org/node/3177488', E_USER_DEPRECATED);
class Statement extends \PDOStatement implements StatementInterface {
public $dbh;
public $allowRowCount = FALSE;
protected function __construct(Connection $dbh) {
$this->dbh = $dbh;
$this
->setFetchMode(\PDO::FETCH_OBJ);
}
public function getConnectionTarget() : string {
return $this->connection
->getTarget();
}
public function execute($args = [], $options = []) {
if (isset($options['fetch'])) {
if (is_string($options['fetch'])) {
$this
->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, $options['fetch']);
}
else {
$this
->setFetchMode($options['fetch']);
}
}
$logger = $this->dbh
->getLogger();
if (!empty($logger)) {
$query_start = microtime(TRUE);
}
$return = parent::execute($args);
if (!empty($logger)) {
$query_end = microtime(TRUE);
$logger
->log($this, $args, $query_end - $query_start, $query_start);
}
return $return;
}
public function getQueryString() {
return $this->queryString;
}
public function fetchCol($index = 0) {
return $this
->fetchAll(\PDO::FETCH_COLUMN, $index);
}
public function fetchAllAssoc($key, $fetch = NULL) {
$return = [];
if (isset($fetch)) {
if (is_string($fetch)) {
$this
->setFetchMode(\PDO::FETCH_CLASS, $fetch);
}
else {
$this
->setFetchMode($fetch);
}
}
foreach ($this as $record) {
$record_key = is_object($record) ? $record->{$key} : $record[$key];
$return[$record_key] = $record;
}
return $return;
}
public function fetchAllKeyed($key_index = 0, $value_index = 1) {
$return = [];
$this
->setFetchMode(\PDO::FETCH_NUM);
foreach ($this as $record) {
$return[$record[$key_index]] = $record[$value_index];
}
return $return;
}
public function fetchField($index = 0) {
return $this
->fetchColumn($index);
}
public function fetchAssoc() {
return $this
->fetch(\PDO::FETCH_ASSOC);
}
public function rowCount() {
if ($this->allowRowCount) {
return parent::rowCount();
}
else {
throw new RowCountException();
}
}
public function setFetchMode($mode, $a1 = NULL, $a2 = []) {
switch (func_num_args()) {
case 1:
return parent::setFetchMode($mode);
case 2:
return parent::setFetchMode($mode, $a1);
case 3:
default:
return parent::setFetchMode($mode, $a1, $a2);
}
}
public function fetchAll($mode = NULL, $column_index = NULL, $constructor_arguments = NULL) {
switch (func_num_args()) {
case 0:
return parent::fetchAll();
case 1:
return parent::fetchAll($mode);
case 2:
return parent::fetchAll($mode, $column_index);
case 3:
default:
return parent::fetchAll($mode, $column_index, $constructor_arguments);
}
}
}
Classes
Name |
Description |
Statement Deprecated |
Default implementation of StatementInterface. |