DatabaseStatementEmpty

  1. drupal
    1. 8
    2. 7

Empty implementation of a database statement.

This class satisfies the requirements of being a database statement/result object, but does not actually contain data. It is useful when developers need to safely return an "empty" result set without connecting to an actual database. Calling code can then treat it the same as if it were an actual result set that happens to contain no records.

See also

SearchQuery

Hierarchy

Functions & methods

NameDescription
DatabaseStatementEmpty::current
DatabaseStatementEmpty::executeExecutes a prepared statement Overrides DatabaseStatementInterface::execute
DatabaseStatementEmpty::fetch
DatabaseStatementEmpty::fetchAll
DatabaseStatementEmpty::fetchAllAssocReturns the result set as an associative array keyed by the given field. Overrides DatabaseStatementInterface::fetchAllAssoc
DatabaseStatementEmpty::fetchAllKeyedReturns the entire result set as a single associative array. Overrides DatabaseStatementInterface::fetchAllKeyed
DatabaseStatementEmpty::fetchAssocFetches the next row and returns it as an associative array. Overrides DatabaseStatementInterface::fetchAssoc
DatabaseStatementEmpty::fetchColReturns an entire single column of a result set as an indexed array. Overrides DatabaseStatementInterface::fetchCol
DatabaseStatementEmpty::fetchFieldReturns a single field from the next record of a result set. Overrides DatabaseStatementInterface::fetchField
DatabaseStatementEmpty::fetchObject
DatabaseStatementEmpty::getQueryStringGets the query string of this statement. Overrides DatabaseStatementInterface::getQueryString
DatabaseStatementEmpty::key
DatabaseStatementEmpty::next
DatabaseStatementEmpty::rewind
DatabaseStatementEmpty::rowCountReturns the number of rows affected by the last SQL statement. Overrides DatabaseStatementInterface::rowCount
DatabaseStatementEmpty::setFetchMode
DatabaseStatementEmpty::valid

includes/database/database.inc, line 2205

View source
<?php
class DatabaseStatementEmpty implements Iterator, DatabaseStatementInterface {

  public function execute($args = array(), $options = array()) {
    return FALSE;
  }

  public function getQueryString() {
    return '';
  }

  public function rowCount() {
    return 0;
  }

  public function setFetchMode($mode, $a1 = NULL, $a2 = array()) {
    return;
  }

  public function fetch($mode = NULL, $cursor_orientation = NULL, $cursor_offset = NULL) {
    return NULL;
  }

  public function fetchField($index = 0) {
    return NULL;
  }

  public function fetchObject() {
    return NULL;
  }

  public function fetchAssoc() {
    return NULL;
  }

  function fetchAll($mode = NULL, $column_index = NULL, array $constructor_arguments = array()) {
    return array();
  }

  public function fetchCol($index = 0) {
    return array();
  }

  public function fetchAllKeyed($key_index = 0, $value_index = 1) {
    return array();
  }

  public function fetchAllAssoc($key, $fetch = NULL) {
    return array();
  }

  /* Implementations of Iterator. */

  public function current() {
    return NULL;
  }

  public function key() {
    return NULL;
  }

  public function rewind() {
    // Nothing to do: our DatabaseStatement can't be rewound.
  }

  public function next() {
    // Do nothing, since this is an always-empty implementation.
  }

  public function valid() {
    return FALSE;
  }
}
?>

Related topics