function PdoTrait::clientSetFetchMode

Sets the default fetch mode for the PDO statement.

Parameters

\Drupal\Core\Database\FetchAs $mode: One of the cases of the FetchAs enum.

int|class-string|null $columnOrClass: If $mode is FetchAs::Column, the index of the column to fetch. If $mode is FetchAs::ClassObject, the FQCN of the object.

list<mixed>|null $constructorArguments: If $mode is FetchAs::ClassObject, the arguments to pass to the constructor.

Return value

bool Returns true on success or false on failure.

1 call to PdoTrait::clientSetFetchMode()
StatementWrapperIterator::setFetchMode in core/lib/Drupal/Core/Database/StatementWrapperIterator.php
Sets the default fetch mode for this statement.

File

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

Class

PdoTrait
A trait for calling \PDOStatement methods.

Namespace

Drupal\Core\Database\Statement

Code

protected function clientSetFetchMode(FetchAs $mode, int|string|null $columnOrClass = NULL, array|null $constructorArguments = NULL) : bool {
    return match ($mode) {    FetchAs::Column => $this->getClientStatement()
            ->setFetchMode(\PDO::FETCH_COLUMN, $columnOrClass ?? $this->fetchOptions['column']),
        FetchAs::ClassObject => $this->getClientStatement()
            ->setFetchMode(\PDO::FETCH_CLASS, $columnOrClass ?? $this->fetchOptions['class'], $constructorArguments ?? $this->fetchOptions['constructor_args']),
        default => $this->getClientStatement()
            ->setFetchMode($this->fetchAsToPdo($mode)),
    
    };
}

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