function StatementBase::setFetchMode
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Database/Statement/StatementBase.php \Drupal\Core\Database\Statement\StatementBase::setFetchMode()
Sets the default fetch mode for this statement.
Parameters
\Drupal\Core\Database\Statement\FetchAs $mode: One of the cases of the FetchAs enum.
string|int|null $a1: An option depending of the fetch mode specified by $mode:
- for FetchAs::Column, the index of the column to fetch;
- for FetchAs::ClassObject, the name of the class to create.
list<mixed> $a2: If $mode is FetchAs::ClassObject, the optional arguments to pass to the object constructor.
Return value
bool TRUE if successful, FALSE if not.
Overrides StatementInterface::setFetchMode
5 calls to StatementBase::setFetchMode()
- Statement::execute in core/
modules/ mysqli/ src/ Driver/ Database/ mysqli/ Statement.php - Executes a prepared statement.
- Statement::__construct in core/
modules/ mysqli/ src/ Driver/ Database/ mysqli/ Statement.php - Constructs a Statement object.
- StatementPrefetchIterator::execute in core/
lib/ Drupal/ Core/ Database/ StatementPrefetchIterator.php - Executes a prepared statement.
- StatementWrapperIterator::execute in core/
lib/ Drupal/ Core/ Database/ StatementWrapperIterator.php - Executes a prepared statement.
- StatementWrapperIterator::__construct in core/
lib/ Drupal/ Core/ Database/ StatementWrapperIterator.php - Constructs a StatementWrapperIterator object.
File
-
core/
lib/ Drupal/ Core/ Database/ Statement/ StatementBase.php, line 210
Class
- StatementBase
- StatementInterface base implementation.
Namespace
Drupal\Core\Database\StatementCode
public function setFetchMode($mode, $a1 = NULL, $a2 = []) {
assert($mode instanceof FetchAs);
$this->fetchMode = $mode;
switch ($mode) {
case FetchAs::ClassObject:
$this->fetchOptions['class'] = $a1;
if ($a2) {
$this->fetchOptions['constructor_args'] = $a2;
}
break;
case FetchAs::Column:
$this->fetchOptions['column'] = $a1;
break;
}
// If the result object is missing, just do with the properties setting.
try {
if ($this->result) {
return $this->result
->setFetchMode($mode, $this->fetchOptions);
}
return TRUE;
} catch (\LogicException) {
return TRUE;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.