Overview
Namespace:FQL\Results
ResultsProvider is the abstract base class for result sets returned by Query::execute(). It implements IteratorAggregate and provides methods to iterate, fetch individual rows, perform aggregate calculations, and export results to a file.
You never instantiate ResultsProvider directly — you receive it from execute().
Subtypes
Query::execute() returns one of two concrete implementations depending on query complexity:
| Class | When used |
|---|---|
Results\Stream | Simple queries without joins or sorting. Processes data lazily as a generator — low memory usage. |
Results\InMemory | Queries with joins, sorting, or DISTINCT. Loads all rows into an ArrayIterator before returning. |
You can force a specific mode by passing the class name to
execute():ResultsProvider interface described below.
Iteration
getIterator()
Returns a Traversable over all result rows. Each row is an associative array.
ResultsProvider implements IteratorAggregate, so you can use it in a foreach loop directly.
Fetching rows
fetchAll()
Yield all rows as a Generator. Optionally hydrate each row into a DTO class.
Fully qualified class name of a DTO. When provided, each row is mapped to an instance of that class using constructor parameters or public properties.
Yields associative arrays (or DTO objects when
$dto is set).fetch()
Return the first row only, or null if the result set is empty.
Optional DTO class name for hydration.
The first row as an associative array, a DTO object, or
null.fetchSingle()
Return a single field value from the first row.
Field name, including dot-notation for nested fields (e.g.
address.city).The value of the field, or
null if the row or field does not exist.fetchNth()
Yield every nth row, or every even/odd row.
- Integer: yield every nth row (1-indexed count).
'even': yield rows at even positions (0-indexed: 0, 2, 4…).'odd': yield rows at odd positions (0-indexed: 1, 3, 5…).
Optional DTO class name.
InvalidArgumentException for invalid $n values.
exists()
Return true if the result set contains at least one row.
Counting
count()
Return the total number of rows in the result set.
Results\Stream caches the count internally after the first call, so repeated count() calls do not re-read the file.Aggregation
These methods iterate the result set and compute aggregate values. ForResults\Stream, computed values are cached so that repeated calls do not re-read the stream.
sum()
Field name to sum. Non-numeric values are treated as
0.avg()
Field name to average.
Number of decimal places in the result (default
2).min()
Field name to find the minimum of.
max()
Field name to find the maximum of.
Exporting
into()
Write all result rows to a file. The output format is determined by the file extension in the FileQuery string.
A file path string (e.g.
output/report.csv) or a FileQuery object. The directory is created automatically if it does not exist.The resolved output file path, or
null when running under EXPLAIN ANALYZE mode.FileQueryException, InvalidFormatException, InvalidArgumentException