execute() on a query returns a ResultsProvider object. This does not immediately process all data — results are lazy by default and only materialized when you iterate or call a fetch method.
ResultsProvider modes
execute() automatically selects the most efficient result mode, but you can override it explicitly:
Queries with
JOIN or ORDER BY always use InMemory mode regardless of the explicit parameter, because those operations require full dataset access.Fetch methods
fetchAll()
Returns aGenerator that yields all result rows. Optionally maps each row to a DTO class:
getIterator()
Returns aTraversable — equivalent to fetchAll() without DTO mapping. Useful in foreach directly on the results object:
fetch()
Returns the first row only, ornull if there are no results:
fetchSingle()
Returns a single field value from the first row. Dot notation is supported for nested fields:fetchNth()
Returns every nth row as aGenerator. Pass an integer for every nth row, or 'even'/'odd' for even/odd-indexed rows (0-based):
exists()
Returnstrue if at least one result row exists. More efficient than count() because it stops after finding the first row:
count()
Returns the total number of result rows:Aggregate methods
These methods compute values over the result set without requiring aGROUP BY in the query:
| Method | Signature | Returns |
|---|---|---|
sum() | sum(string $field): float | Sum of all values in the field |
avg() | avg(string $field, int $decimalPlaces = 2): float | Average value, rounded to given decimal places |
max() | max(string $field): float | Maximum value in the field |
min() | min(string $field): float | Minimum value in the field |
DTO mapping
All fetch methods that return rows accept an optionalclass-string $dto parameter. When provided, each row is mapped to an instance of the given class using reflection.
Anonymous class DTO
Named class DTO
Constructor-based DTO
If the class has a constructor, FiQueLa maps field values to constructor parameters by name:DTO mapping uses PHP reflection. Public properties are populated by matching field names. If a constructor is present, parameters are matched by name from the result row.
INTO — exporting results
After executing, you can pipe results directly to an output file usinginto():
INTO format reference.