Drupal 8  8.0.2
StatementInterface Interface Reference
Inheritance diagram for StatementInterface:

Public Member Functions

 execute ($args=array(), $options=array())
 
 getQueryString ()
 
 rowCount ()
 
 setFetchMode ($mode, $a1=NULL, $a2=array())
 
 fetch ($mode=NULL, $cursor_orientation=NULL, $cursor_offset=NULL)
 
 fetchField ($index=0)
 
 fetchObject ()
 
 fetchAssoc ()
 
 fetchAll ($mode=NULL, $column_index=NULL, $constructor_arguments=NULL)
 
 fetchCol ($index=0)
 
 fetchAllKeyed ($key_index=0, $value_index=1)
 
 fetchAllAssoc ($key, $fetch=NULL)
 

Detailed Description

Represents a prepared statement.

Child implementations should either extend PDOStatement:

class Drupal\Core\Database\Driver\oracle\Statement extends PDOStatement implements Drupal\Core\Database\StatementInterface {}

or define their own class. If defining their own class, they will also have to implement either the Iterator or IteratorAggregate interface before Drupal:

class Drupal\Core\Database\Driver\oracle\Statement implements Iterator, Drupal\Core\Database\StatementInterface {}

Member Function Documentation

execute (   $args = array(),
  $options = array() 
)

Constructs a new PDOStatement object.

The PDO manual does not document this constructor, but when overriding the PDOStatement class with a custom without this constructor, PDO will throw the internal exception/warning:

"PDO::query(): SQLSTATE[HY000]: General error: user-supplied statement does not accept constructor arguments"

PDO enforces that the access type of this constructor must be protected, and lastly, it also enforces that a custom PDOStatement interface (like this) omits the constructor (declaring it results in fatal errors complaining about "the access type must not be public" if it is public, and "the access type must be omitted" if it is protected; i.e., conflicting statements). The access type has to be protected. Executes a prepared statement

Parameters
$argsAn array of values with as many elements as there are bound parameters in the SQL statement being executed.
$optionsAn array of options for this query.
Returns
TRUE on success, or FALSE on failure.

Implemented in StatementPrefetch, Statement, Statement, and StatementEmpty.

fetch (   $mode = NULL,
  $cursor_orientation = NULL,
  $cursor_offset = NULL 
)

Fetches the next row from a result set.

See http://php.net/manual/pdo.constants.php for the definition of the constants used.

Parameters
$modeOne of the PDO::FETCH_* constants. Default to what was specified by setFetchMode().
$cursor_orientationNot implemented in all database drivers, don't use.
$cursor_offsetNot implemented in all database drivers, don't use.
Returns
A result, formatted according to $mode.

Implemented in StatementPrefetch, and StatementEmpty.

Referenced by Statement\fetchAssoc().

Here is the caller graph for this function:

fetchAll (   $mode = NULL,
  $column_index = NULL,
  $constructor_arguments = NULL 
)

Returns an array containing all of the result set rows.

Parameters
$modeOne of the PDO::FETCH_* constants.
$column_indexIf $mode is PDO::FETCH_COLUMN, the index of the column to fetch.
$constructor_argumentsIf $mode is PDO::FETCH_CLASS, the arguments to pass to the constructor.
Returns
An array of results.

Implemented in StatementPrefetch, Statement, and StatementEmpty.

fetchAllAssoc (   $key,
  $fetch = NULL 
)

Returns the result set as an associative array keyed by the given field.

If the given key appears multiple times, later records will overwrite earlier ones.

Parameters
$keyThe name of the field on which to index the array.
$fetchThe fetchmode to use. If set to PDO::FETCH_ASSOC, PDO::FETCH_NUM, or PDO::FETCH_BOTH the returned value with be an array of arrays. For any other value it will be an array of objects. By default, the fetch mode set for the query will be used.
Returns
An associative array, or an empty array if there is no result set.

Implemented in StatementPrefetch, StatementEmpty, and Statement.

fetchAllKeyed (   $key_index = 0,
  $value_index = 1 
)

Returns the entire result set as a single associative array.

This method is only useful for two-column result sets. It will return an associative array where the key is one column from the result set and the value is another field. In most cases, the default of the first two columns is appropriate.

Note that this method will run the result set to the end.

Parameters
$key_indexThe numeric index of the field to use as the array key.
$value_indexThe numeric index of the field to use as the array value.
Returns
An associative array, or an empty array if there is no result set.

Implemented in StatementPrefetch, Statement, and StatementEmpty.

fetchAssoc ( )

Fetches the next row and returns it as an associative array.

This method corresponds to PDOStatement::fetchObject(), but for associative arrays. For some reason PDOStatement does not have a corresponding array helper method, so one is added.

Returns
An associative array, or FALSE if there is no next row.

Implemented in StatementPrefetch, Statement, and StatementEmpty.

fetchCol (   $index = 0)

Returns an entire single column of a result set as an indexed array.

Note that this method will run the result set to the end.

Parameters
$indexThe index of the column number to fetch.
Returns
An indexed array, or an empty array if there is no result set.

Implemented in StatementPrefetch, StatementEmpty, and Statement.

fetchField (   $index = 0)

Returns a single field from the next record of a result set.

Parameters
$indexThe numeric index of the field to return. Defaults to the first field.
Returns
A single field from the next record, or FALSE if there is no next record.

Implemented in StatementPrefetch, Statement, and StatementEmpty.

fetchObject ( )

Fetches the next row and returns it as an object.

The object will be of the class specified by StatementInterface::setFetchMode() or stdClass if not specified.

Implemented in StatementEmpty.

getQueryString ( )

Gets the query string of this statement.

Returns
The query string, in its form with placeholders.

Implemented in StatementPrefetch, Statement, and StatementEmpty.

Referenced by Log\log().

Here is the caller graph for this function:

rowCount ( )

Returns the number of rows affected by the last SQL statement.

Returns
The number of rows affected by the last DELETE, INSERT, or UPDATE statement executed or throws if the last executed statement was SELECT.
Exceptions
\Drupal\Core\Database\RowCountException

Implemented in StatementPrefetch, Statement, and StatementEmpty.

setFetchMode (   $mode,
  $a1 = NULL,
  $a2 = array() 
)

Sets the default fetch mode for this statement.

See http://php.net/manual/pdo.constants.php for the definition of the constants used.

Parameters
$modeOne of the PDO::FETCH_* constants.
$a1An option depending of the fetch mode specified by $mode:
  • for PDO::FETCH_COLUMN, the index of the column to fetch
  • for PDO::FETCH_CLASS, the name of the class to create
  • for PDO::FETCH_INTO, the object to add the data to
$a2If $mode is PDO::FETCH_CLASS, the optional arguments to pass to the constructor.

Implemented in StatementPrefetch, Statement, and StatementEmpty.


The documentation for this interface was generated from the following file: