class Statement

Same name in this branch

Default implementation of StatementInterface.

PDO allows us to extend the PDOStatement class to provide additional functionality beyond that offered by default. We do need extra functionality. By default, this class is not driver-specific. If a given driver needs to set a custom statement class, it may do so in its constructor.

Hierarchy

Expanded class hierarchy of Statement

See also

http://php.net/pdostatement

1 string reference to 'Statement'
EasyRdf_Parser_RdfXml::reify in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/RdfXml.php
@ignore

File

drupal/core/lib/Drupal/Core/Database/Statement.php, line 24
Definition of Drupal\Core\Database\StatementBase

Namespace

Drupal\Core\Database
View source
class Statement extends PDOStatement implements StatementInterface {

  /**
   * Reference to the database connection object for this statement.
   *
   * The name $dbh is inherited from PDOStatement.
   *
   * @var DatabaseConnection
   */
  public $dbh;
  protected function __construct(Connection $dbh) {
    $this->dbh = $dbh;
    $this
      ->setFetchMode(PDO::FETCH_OBJ);
  }
  public function execute($args = array(), $options = array()) {
    if (isset($options['fetch'])) {
      if (is_string($options['fetch'])) {

        // PDO::FETCH_PROPS_LATE tells __construct() to run before properties
        // are added to the object.
        $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);
    }
    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 = array();
    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 = array();
    $this
      ->setFetchMode(PDO::FETCH_NUM);
    foreach ($this as $record) {
      $return[$record[$key_index]] = $record[$value_index];
    }
    return $return;
  }
  public function fetchField($index = 0) {

    // Call PDOStatement::fetchColumn to fetch the field.
    return $this
      ->fetchColumn($index);
  }
  public function fetchAssoc() {

    // Call PDOStatement::fetch to fetch the row.
    return $this
      ->fetch(PDO::FETCH_ASSOC);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Statement::$dbh public property Reference to the database connection object for this statement.
Statement::execute public function Executes a prepared statement Overrides StatementInterface::execute
Statement::fetchAllAssoc public function Returns the result set as an associative array keyed by the given field. Overrides StatementInterface::fetchAllAssoc
Statement::fetchAllKeyed public function Returns the entire result set as a single associative array. Overrides StatementInterface::fetchAllKeyed
Statement::fetchAssoc public function Fetches the next row and returns it as an associative array. Overrides StatementInterface::fetchAssoc
Statement::fetchCol public function Returns an entire single column of a result set as an indexed array. Overrides StatementInterface::fetchCol
Statement::fetchField public function Returns a single field from the next record of a result set. Overrides StatementInterface::fetchField
Statement::getQueryString public function Gets the query string of this statement. Overrides StatementInterface::getQueryString
Statement::__construct protected function
StatementInterface::rowCount public function Returns the number of rows affected by the last SQL statement. 2