class Result implements Traversable, Countable (View source)

A query result.

See [Fetching Results](pq/Result/: Fetching Results) for a general overview.

Constants

EMPTY_QUERY

The query sent to the server was empty.

COMMAND_OK

The query did not generate a result set and completed successfully.

TUPLES_OK

The query successfully generated a result set.

SINGLE_TUPLE

The result contains a single row of the result set when using pq\Connection::$unbuffered.

COPY_OUT

COPY data can be received from the server.

COPY_IN

COPY data can be sent to the server.

COPY_BOTH

COPY in/out data transfer in progress.

BAD_RESPONSE

The server sent a bad response.

NONFATAL_ERROR

A nonfatal error (notice or warning) occurred.

FATAL_ERROR

A fatal error occurred.

FETCH_ARRAY

Fetch rows numerically indexed, where the index start with 0.

FETCH_ASSOC

Fetch rows associatively indexed by column name.

FETCH_OBJECT

Fetch rows as stdClass instance, where the column names are the property names.

CONV_BOOL

Automatically convert 'f' and 't' to FALSE and TRUE and vice versa.

CONV_INT

Automatically convert integral strings to either int if it fits into maximum integer size or else to float and vice versa.

CONV_FLOAT

Automatically convert floating point numbers.

CONV_SCALAR

Do all scalar conversions listed above.

CONV_ARRAY

Automatically convert arrays.

CONV_DATETIME

Automatically convert date strings to pq\DateTime and vice versa.

CONV_JSON

Automatically convert JSON.

CONV_ALL

Do all of the above.

Properties

int read-only $status

A status constant.

string read-only $statusMessage

The accompanying status message.

string read-only $errorMessage

Any error message if $status indicates an error.

int read-only $numRows

The number of rows in the result set.

int read-only $numCols

The number of fields in a single tuple of the result set.

int read-only $affectedRows

The number of rows affected by a statement.

array read-only $diag

Error details. See PQresultErrorField docs.

int $fetchType

The type of return value the fetch methods should return when no fetch type argument was given. Defaults to pq\Connection::$defaultFetchType.

int $autoConvert

What type of conversions to perform automatically.

Methods

bool
bind(mixed $col, mixed $var)

Bind a variable to a result column.

int
count()

Count number of rows in this result set.

array
desc()

Describe a prepared statement.

array
fetchAll(int $fetch_type = null)

Fetch all rows at once.

array
fetchAllCols(int $col = 0)

Fetch all rows of a single column.

array|null
fetchBound()

Iteratively fetch a row into bound variables.

bool|null
fetchCol(mixed $ref, mixed $col = 0)

Iteratively fetch a single column.

array|object|null
fetchRow(int $fetch_type = null)

Iteratively fetch a row.

array|object
map(mixed $keys = 0, mixed $vals = null, int $fetch_type = null)

Fetch the complete result set as a simple map, a multi dimensional array, each dimension indexed by a column.

Details

bool bind(mixed $col, mixed $var)

Bind a variable to a result column.

See pq\Result::fetchBound().

Parameters

mixed $col

The column name or index to bind to.

mixed $var

The variable reference.

Return Value

bool success.

Exceptions

InvalidArgumentException
BadMethodCallException

int count()

Count number of rows in this result set.

Return Value

int

The custom count as an integer.

The return value is cast to an integer.

Exceptions

InvalidArgumentException
BadMethodCallException

array desc()

Describe a prepared statement.

NOTE: This will only return meaningful information for a result of pq\Statement::desc().

Return Value

array

list of parameter type OIDs for the prepared statement.

Exceptions

InvalidArgumentException
BadMethodCallException

array fetchAll(int $fetch_type = null)

Fetch all rows at once.

Parameters

int $fetch_type

The type the return value should have, see pq\Result::FETCH_* constants, defaults to pq\Result::$fetchType.

Return Value

array

all fetched rows.

Exceptions

InvalidArgumentException
BadMethodCallException

array fetchAllCols(int $col = 0)

Fetch all rows of a single column.

Parameters

int $col

The column name or index to fetch.

Return Value

array

list of column values.

Exceptions

InvalidArgumentException
BadMethodCallException
RuntimeException

array|null fetchBound()

Iteratively fetch a row into bound variables.

See pq\Result::bind().

Return Value

array|null

array the fetched row as numerically indexed array. or NULL when iteration ends.

Exceptions

InvalidArgumentException
BadMethodCallException
RuntimeException

bool|null fetchCol(mixed $ref, mixed $col = 0)

Iteratively fetch a single column.

Parameters

mixed $ref

The variable where the column value will be stored in.

mixed $col

The column name or index.

Return Value

bool|null

bool success. or NULL when iteration ends.

Exceptions

InvalidArgumentException
BadMethodCallException
RuntimeException

array|object|null fetchRow(int $fetch_type = null)

Iteratively fetch a row.

Parameters

int $fetch_type

The type the return value should have, see pq\Result::FETCH_* constants, defaults to pq\Result::$fetchType.

Return Value

array|object|null

array numerically indexed for pq\Result::FETCH_ARRAY or array associatively indexed for pq\Result::FETCH_ASSOC or object stdClass instance for pq\Result::FETCH_OBJECT or NULL when iteration ends.

Exceptions

InvalidArgumentException
BadMethodCallException
RuntimeException

array|object map(mixed $keys = 0, mixed $vals = null, int $fetch_type = null)

Fetch the complete result set as a simple map, a multi dimensional array, each dimension indexed by a column.

Parameters

mixed $keys

The the column indices/names used to index the map.

mixed $vals

The column indices/names which should build up the leaf entry of the map.

int $fetch_type

The type the return value should have, see pq\Result::FETCH_* constants, defaults to pq\Result::$fetchType.

Return Value

array|object

the mapped columns.

Exceptions

InvalidArgumentException
BadMethodCallException
RuntimeException