class Result
Same name in this branch
- 11.x core/modules/views/src/Plugin/views/area/Result.php \Drupal\views\Plugin\views\area\Result
Same name and namespace in other branches
- 9 core/modules/views/src/Plugin/views/area/Result.php \Drupal\views\Plugin\views\area\Result
- 8.9.x core/modules/views/src/Plugin/views/area/Result.php \Drupal\views\Plugin\views\area\Result
- 10 core/modules/views/src/Plugin/views/area/Result.php \Drupal\views\Plugin\views\area\Result
Class for mysqli-provided results of a data query language (DQL) statement.
Hierarchy
- class \Drupal\Core\Database\Statement\ResultBase uses \Drupal\Core\Database\FetchModeTrait
- class \Drupal\mysqli\Driver\Database\mysqli\Result uses \Drupal\Core\Database\FetchModeTrait implements \Drupal\Core\Database\Statement\ResultBase
Expanded class hierarchy of Result
10 string references to 'Result'
- ContentEntityBaseUnitTest::providerGet in core/
tests/ Drupal/ Tests/ Core/ Entity/ ContentEntityBaseUnitTest.php - Data provider for testGet().
- MessagesTest::setUp in core/
modules/ views/ tests/ src/ Unit/ Plugin/ area/ MessagesTest.php - ResultTest::setUp in core/
modules/ views/ tests/ src/ Unit/ Plugin/ area/ ResultTest.php - views.area.schema.yml in core/
modules/ views/ config/ schema/ views.area.schema.yml - core/modules/views/config/schema/views.area.schema.yml
- views.view.test_area_result.yml in core/
modules/ views/ tests/ modules/ views_test_config/ test_views/ views.view.test_area_result.yml - core/modules/views/tests/modules/views_test_config/test_views/views.view.test_area_result.yml
File
-
core/
modules/ mysqli/ src/ Driver/ Database/ mysqli/ Result.php, line 15
Namespace
Drupal\mysqli\Driver\Database\mysqliView source
class Result extends ResultBase {
use FetchModeTrait;
/**
* Constructor.
*
* @param \Drupal\Core\Database\Statement\FetchAs $fetchMode
* The fetch mode.
* @param array{class: class-string, constructor_args: list<mixed>, column: int, cursor_orientation?: int, cursor_offset?: int} $fetchOptions
* The fetch options.
* @param \mysqli_result|false $mysqliResult
* The MySQLi result object.
* @param \mysqli $mysqliConnection
* Client database connection object.
*/
public function __construct(FetchAs $fetchMode, array $fetchOptions, protected readonly \mysqli_result|false $mysqliResult, protected readonly \mysqli $mysqliConnection) {
parent::__construct($fetchMode, $fetchOptions);
}
/**
* {@inheritdoc}
*/
public function rowCount() : ?int {
// The most accurate value to return for Drupal here is the first
// occurrence of an integer in the string stored by the connection's
// $info property.
// This is something like 'Rows matched: 1 Changed: 1 Warnings: 0' for
// UPDATE or DELETE operations, 'Records: 2 Duplicates: 1 Warnings: 0'
// for INSERT ones.
// This however requires a regex parsing of the string which is expensive;
// $affected_rows would be less accurate but much faster. We would need
// Drupal to be less strict in testing, and never rely on this value in
// runtime (which would be healthy anyway).
if ($this->mysqliConnection->info !== NULL) {
$matches = [];
if (preg_match('/\\s(\\d+)\\s/', $this->mysqliConnection->info, $matches) === 1) {
return (int) $matches[0];
}
else {
throw new DatabaseExceptionWrapper('Invalid data in the $info property of the mysqli connection - ' . $this->mysqliConnection->info);
}
}
elseif ($this->mysqliConnection->affected_rows !== NULL) {
return $this->mysqliConnection->affected_rows;
}
throw new DatabaseExceptionWrapper('Unable to retrieve affected rows data');
}
/**
* {@inheritdoc}
*/
public function setFetchMode(FetchAs $mode, array $fetchOptions) : bool {
// There are no methods to set fetch mode in \mysqli_result.
return TRUE;
}
/**
* {@inheritdoc}
*/
public function fetch(FetchAs $mode, array $fetchOptions) : array|object|int|float|string|bool|null {
assert($this->mysqliResult instanceof \mysqli_result);
$mysqli_row = $this->mysqliResult
->fetch_assoc();
if (!$mysqli_row) {
return FALSE;
}
// Stringify all non-NULL column values.
$row = array_map(fn($value) => $value === NULL ? NULL : (string) $value, $mysqli_row);
return $this->assocToFetchMode($row, $mode, $fetchOptions);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
FetchModeTrait::$fetchModeLiterals | protected | property | Map FETCH_* modes to their literal for inclusion in messages. | ||
FetchModeTrait::$supportedFetchModes | protected | property | The fetch modes supported. | ||
FetchModeTrait::assocToClass | protected | function | Converts a row of data in FETCH_ASSOC format to FETCH_CLASS. | ||
FetchModeTrait::assocToColumn | protected | function | Converts a row of data in FETCH_ASSOC format to FETCH_COLUMN. | ||
FetchModeTrait::assocToFetchMode | protected | function | Converts a row of data in associative format to a specified format. | ||
FetchModeTrait::assocToNum | protected | function | Converts a row of data in FETCH_ASSOC format to FETCH_NUM. | ||
FetchModeTrait::assocToObj | protected | function | Converts a row of data in FETCH_ASSOC format to FETCH_OBJ. | ||
Result::fetch | public | function | Fetches the next row. | Overrides ResultBase::fetch | |
Result::rowCount | public | function | Returns the number of rows matched by the last SQL statement. | Overrides ResultBase::rowCount | |
Result::setFetchMode | public | function | Sets the default fetch mode for this result set. | Overrides ResultBase::setFetchMode | |
Result::__construct | public | function | Constructor. | Overrides ResultBase::__construct | |
ResultBase::fetchAll | public | function | Returns an array containing all of the result set rows. | 1 | |
ResultBase::fetchAllAssoc | public | function | Returns the result set as an associative array keyed by the given column. | ||
ResultBase::fetchAllKeyed | public | function | Returns the entire result set as a single associative array. | 1 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.