function StatementPrefetchIterator::setFetchMode

Sets the default fetch mode for this statement.

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

Parameters

$mode: One of the \PDO::FETCH_* constants.

$a1: An 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

$a2: If $mode is \PDO::FETCH_CLASS, the optional arguments to pass to the constructor.

Overrides StatementInterface::setFetchMode

1 call to StatementPrefetchIterator::setFetchMode()
StatementPrefetchIterator::execute in core/lib/Drupal/Core/Database/StatementPrefetchIterator.php
Executes a prepared statement.

File

core/lib/Drupal/Core/Database/StatementPrefetchIterator.php, line 209

Class

StatementPrefetchIterator
An implementation of StatementInterface that prefetches all data.

Namespace

Drupal\Core\Database

Code

public function setFetchMode($mode, $a1 = NULL, $a2 = []) {
    if (!in_array($mode, $this->supportedFetchModes)) {
        @trigger_error('Fetch mode ' . ($this->fetchModeLiterals[$mode] ?? $mode) . ' is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use supported modes only. See https://www.drupal.org/node/3377999', E_USER_DEPRECATED);
    }
    $this->defaultFetchStyle = $mode;
    switch ($mode) {
        case \PDO::FETCH_CLASS:
            $this->fetchOptions['class'] = $a1;
            if ($a2) {
                $this->fetchOptions['constructor_args'] = $a2;
            }
            break;
        case \PDO::FETCH_COLUMN:
            $this->fetchOptions['column'] = $a1;
            break;
        case \PDO::FETCH_INTO:
            $this->fetchOptions['object'] = $a1;
            break;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.