Skip to content

ResultInterface

Alexander Saal edited this page Aug 4, 2025 · 1 revision

ResultInterface

Constants & Methods

interface ResultInterface
{
    /** Data indexed by column names (associative array). */
    public const MODE_ASSOC = 2;

    /** Default fetch mode if none specified. */
    public const MODE_DEFAULT = 0;

    /** Column names as top-level keys; rows as second-level keys. */
    public const MODE_FLIPPED = 4;

    /** Data as objects with properties corresponding to column names. */
    public const MODE_OBJECT = 3;

    /** Data indexed numerically by column order. */
    public const MODE_ORDERED = 1;

    /**
     * Fetches all rows from the query.
     *
     * @param int $fetchMode The fetch mode to use (default: MODE_DEFAULT).
     * @param bool $rekey if set to true, return array will have the first column as
     * its first dimension
     * @param bool $force_array used only when the query returns exactly two
     * columns. If true, the values of the returned array will be one-element
     * arrays instead of scalars.
     * @param bool $group if true, the values of the returned array is wrapped in another array.  If the same
     * key value (in the first column) repeats itself, the values will be appended to this array instead of
     * overwriting the existing values.
     *
     * @return array<mixed>  data array on success, a error on failure.
     */
    public function fetchAll(
        int $fetchMode = self::MODE_DEFAULT,
        $rekey = false,
        $force_array = false,
        $group = false,
    );

    /**
     * Fetches a single column of data from the result.
     *
     * @param int $colNum The column number to fetch (default: 0).
     *
     * @return array<mixed> The values of the specified column.
     */
    public function fetchCol(int $colNum = 0);

    /**
     * Fetches a single value from the result.
     *
     * @param int $colNum The column number to fetch (default: 0).
     * @param int|null $rowNum The row number to fetch (default: first row).
     *
     * @return mixed The fetched value.
     */
    public function fetchOne(int $colNum = 0, ?int $rowNum = null);

    /**
     * Fetches a single row from the result.
     *
     * @param int $fetchMode The fetch mode to use (default: MODE_DEFAULT).
     * @param int|null $rowNum The row number to fetch (default: first row).
     *
     * @return array<mixed> data array on success, a error on failure.
     */
    public function fetchRow(int $fetchMode = self::MODE_DEFAULT, ?int $rowNum = null);
}

Example

Clone this wiki locally