-
Notifications
You must be signed in to change notification settings - Fork 2
ResultSet
Alexey Borzov edited this page Sep 8, 2017
·
1 revision
This class is a wrapper around pgsql result resource. An instance of it is returned by Connection::execute()
, Connection::executeParams()
, PreparedStatement::execute()
if the executed query returned rows. This instance receives the implementation of TypeConverterFactory
used by the Connection
executing the query and uses it to convert strings in query result to PHP native types.
Usage examples for query results.
ResultSet
implements Iterator
, Countable
, and ArrayAccess
SPL interfaces which allow, respectively
- Iteration over rows with
foreach ($result as $row)
- Getting number of returned rows with
count($result)
- Accessing a specific result row with
$result[$index]
-
fetchAll(int|null $mode = null, string|int $keyColumn = null, bool $forceArray = false, bool $group = false): array
- Returns an array containing all rows of the result set-
$mode
- Fetch mode, eitherPGSQL_ASSOC
orPGSQL_NUM
. Ifnull
, mode set withsetMode()
will be used. -
$keyColumn
- Either a column name or an index (0-based). If given, values of this column will be used as keys in the outer array. -
$forceArray
- Used only with$keyColumn
when the query returns exactly two columns. Iftrue
the values will be one element arrays with non-key column's values, instead of values directly. -
$group
- Iftrue
, the values in the returned array are wrapped in another array. If there are duplicate values in key column, values of other columns will be appended to this array instead of overwriting previous ones.
-
-
fetchColumn(string|int $fieldIndex): array
- Returns an array containing all values from a given column in the result set.$fieldIndex
is either a 0-based index or a name of result column. -
getFieldCount(): int
- Returns the number of fields in the result. -
getFieldNames(): array
- Returns the names of fields in the result. -
setType(string|int $fieldIndex, mixed $type): $this
- Sets the type for a result column. Here$fieldIndex
is either a 0-based index or a name of result column,$type
is either aTypeConverter
instance or a type specification forTypeConverterFactory
. Note that it is not usually needed to specify result types: they are deduced from database metadata. -
setMode(int $mode = PGSQL_ASSOC): $this
- Sets how the returned rows are indexed. It accepts eitherPGSQL_ASSOC
orPGSQL_NUM
constants used bypg_fetch_row()
.