PDO
PDO
PDO result wrapper for Hazaar DBI, providing methods to interact with PDOStatement results.
class PDO extends \Hazaar\DBI\ResultExtends: Hazaar\DBI\Result
Supports fetching rows, columns, objects, and processing result metadata for advanced type handling.
Properties
statement
The underlying PDOStatement for this result.
private \PDOStatement $statementType: PDOStatement
typeMap
private array $typeMap = array (
'numeric' => 'int',
'int2' => 'int',
'int4' => 'int',
'int8' => 'int',
'float8' => 'float',
'timestamp' => 'Hazaar\\Util\\DateTime',
'timestamptz' => 'Hazaar\\Util\\DateTime',
'date' =>
array (
0 => 'Hazaar\\Util\\DateTime',
1 =>
array (
'format' => 'Y-m-d',
),
),
'bool' => 'boolean',
'money' => 'Hazaar\\Money',
'bytea' =>
array (
0 => 'string',
1 =>
array (
'prepare' => 'stream_get_contents',
),
),
)Type: array
Methods
__construct
Construct a new PDO result wrapper for the given PDOStatement.
public __construct(\PDOStatement $statement): voidParameters
| Parameter | Type | Description |
|---|---|---|
$statement | PDOStatement | the PDO statement to wrap |
createWithAdapter
Create a new PDO result wrapper and associate it with a DBI adapter.
public createWithAdapter(Adapter $adapter, \PDOStatement $statement): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$adapter | Hazaar\DBI\Adapter | the DBI adapter instance |
$statement | PDOStatement | the PDO statement to wrap |
toString
Get the SQL query string for this result.
public toString(): stringReturns: string
rowCount
Get the number of rows affected or returned by the query.
public rowCount(): intReturns: int
columnCount
Get the number of columns in the result set.
public columnCount(): intReturns: int
fetch
A grouped/joined query can easily select two same-named columns from different tables
public fetch(int $fetchStyle = '\PDO::FETCH_ASSOC', int $cursorOrientation = '\PDO::FETCH_ORI_NEXT', int $cursorOffset): array|falseReturns: array|false
(e.g. both sides of a join having a uuid column), and FETCH_ASSOC silently collapses those to whichever one PDO fetched last -- discarding the other before this class ever sees it. FETCH_NAMED instead returns an array of values for any column name that repeats, keeping both available, which is what prepareResult()'s select-group handling needs.
FETCH_ASSOC is still the default for every other query, to avoid changing the shape of $record (scalar vs one-element array) for existing callers that don't use select groups and have never had to think about this. Only upgrade to FETCH_NAMED automatically when the caller left $fetchStyle at that default AND this query actually has select groups (and hasn't been told via setClobberDupNamedCols() to keep the old clobbering behaviour anyway) -- an explicit, non-default $fetchStyle is always respected as-is.
Parameters
| Parameter | Type | Description |
|---|---|---|
$fetchStyle | int | |
$cursorOrientation | int | |
$cursorOffset | int |
fetchAll
See fetch() for why FETCH_ASSOC stays the default here, upgraded to FETCH_NAMED only when
public fetchAll(int $fetchMode = '\PDO::FETCH_ASSOC', mixed $fetchArgument): arrayReturns: array
this query has select groups (and clobbering hasn't been explicitly requested).
Parameters
| Parameter | Type | Description |
|---|---|---|
$fetchMode | int | |
$fetchArgument | mixed |
fetchColumn
Fetch a single column from the next row in the result set.
public fetchColumn(int $columnNumber): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$columnNumber | int | the column index to fetch (default 0) |
fetchObject
public fetchObject(string $className = 'stdClass', array $constructorArgs): false|objectReturns: false|object
Parameters
| Parameter | Type | Description |
|---|---|---|
$className | string | |
$constructorArgs | array |
row
Fetch the next row as a Row object, with optional cursor orientation and offset.
public row(int $cursorOrientation = '\PDO::FETCH_ORI_NEXT', int $offset): ?RowReturns: Hazaar\DBI\Row
Parameters
| Parameter | Type | Description |
|---|---|---|
$cursorOrientation | int | cursor orientation constant (default FETCH_ORI_NEXT) |
$offset | int | row offset (default 0) |
rows
public rows(): ?arrayReturns: array
prepareResult
protected prepareResult(array $record): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$record | array |
applyPrepareCallbacks
Applies each column's prepare callback (see $typeMap, eg; bytea's stream_get_contents)
private applyPrepareCallbacks(array $record): voidReturns: void
to its fetched value.
Columns already handled via $this->arrayColumns (array/json/record types) are skipped here since prepareResult() applies their transformation separately below; running both would double-process the value.
Parameters
| Parameter | Type | Description |
|---|---|---|
$record | array |
processStatement
Process the PDOStatement metadata and populate column type information.
private processStatement(\PDOStatement $statement): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$statement | PDOStatement | the PDO statement to process |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000