function PdoTrait::pdoToFetchAs

Converts a \PDO::FETCH_* constant value to a FetchAs mode.

Parameters

int $mode: The \PDO::FETCH_* constant value.

Return value

\Drupal\Core\Database\FetchAs A FetchAs mode.

4 calls to PdoTrait::pdoToFetchAs()
StatementBase::fetch in core/lib/Drupal/Core/Database/Statement/StatementBase.php
Fetches the next row from a result set.
StatementBase::fetchAll in core/lib/Drupal/Core/Database/Statement/StatementBase.php
Returns an array containing all of the result set rows.
StatementBase::fetchAllAssoc in core/lib/Drupal/Core/Database/Statement/StatementBase.php
Returns the result set as an associative array keyed by the given field.
StatementBase::setFetchMode in core/lib/Drupal/Core/Database/Statement/StatementBase.php
Sets the default fetch mode for this statement.

File

core/lib/Drupal/Core/Database/Statement/PdoTrait.php, line 40

Class

PdoTrait
A trait for calling \PDOStatement methods.

Namespace

Drupal\Core\Database\Statement

Code

protected function pdoToFetchAs(int $mode) : FetchAs {
    return match ($mode) {    \PDO::FETCH_ASSOC => FetchAs::Associative,
        \PDO::FETCH_CLASS, \PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE => FetchAs::ClassObject,
        \PDO::FETCH_COLUMN => FetchAs::Column,
        \PDO::FETCH_NUM => FetchAs::List,
        \PDO::FETCH_OBJ => FetchAs::Object,
        default => throw new \RuntimeException('Fetch mode ' . ($this->fetchModeLiterals[$mode] ?? $mode) . ' is not supported. Use supported modes only.'),
    
    };
}

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