Fr3nch13/CakePHP Utilities

BufferedStatement
in package
implements Iterator, StatementInterface uses TypeConverterTrait

A statement decorator that implements buffered results.

This statement decorator will save fetched results in memory, allowing the iterator to be rewound and reused.

Table of Contents

Interfaces

Iterator
StatementInterface
Represents a database statement. Concrete implementations can either use PDOStatement or a native driver

Properties

$_allFetched  : bool
If true, all rows were fetched
$_driver  : DriverInterface
The driver for the statement
$_hasExecuted  : bool
Whether this statement has already been executed
$buffer  : array<int, array<string|int, mixed>>
The in-memory cache containing results from previous iterators
$index  : int
The current iterator index.
$statement  : StatementInterface
The decorated statement

Methods

__construct()  : mixed
Constructor
__get()  : string|null
Magic getter to return $queryString as read-only.
bind()  : void
Binds a set of values to statement object with corresponding type
bindValue()  : void
Assign a value to a positional or named variable in prepared query. If using positional variables you need to start with index one, if using named params then just use the name in any order.
cast()  : array<string|int, mixed>
Converts a give value to a suitable database value based on type and return relevant internal statement type
closeCursor()  : void
Closes a cursor in the database, freeing up any resources and memory allocated to it. In most cases you don't need to call this method, as it is automatically called after fetching all results from the result set.
columnCount()  : int
Returns the number of columns this statement's results will contain
count()  : int
Statements can be passed as argument for count() to return the number for affected rows from last execution.
current()  : mixed
Returns the current record in the iterator
errorCode()  : string|int
Returns the error code for the last error that occurred when executing this statement
errorInfo()  : array<string|int, mixed>
Returns the error information for the last error that occurred when executing this statement
execute()  : bool
Executes the statement by sending the SQL query to the database. It can optionally take an array or arguments to be bound to the query variables. Please note that binding parameters from this method will not perform any custom type conversion as it would normally happen when calling `bindValue`
fetch()  : array<string|int, mixed>|false
Returns the next row for the result set after executing this statement.
fetchAll()  : array<string|int, mixed>|false
Returns an array with all rows resulting from executing this statement
fetchAssoc()  : array<string|int, mixed>
fetchColumn()  : mixed
Returns the value of the result at position.
getInnerStatement()  : StatementInterface
Get the wrapped statement
key()  : mixed
Returns the current key in the iterator
lastInsertId()  : string|int
Returns the latest primary inserted using this statement
matchTypes()  : array<string|int, mixed>
Matches columns to corresponding types
next()  : void
Advances the iterator pointer to the next element
rewind()  : void
Rewinds the collection
rowCount()  : int
Returns the number of rows affected by this SQL statement
valid()  : bool
Returns whether the iterator has more elements
_reset()  : void
Reset all properties

Properties

$_allFetched

If true, all rows were fetched

protected bool $_allFetched = false

$_hasExecuted

Whether this statement has already been executed

protected bool $_hasExecuted = false

$buffer

The in-memory cache containing results from previous iterators

protected array<int, array<string|int, mixed>> $buffer = []

Methods

__get()

Magic getter to return $queryString as read-only.

public __get(string $property) : string|null
Parameters
$property : string

internal property to get

Return values
string|null

bind()

Binds a set of values to statement object with corresponding type

public bind(array<string|int, mixed> $params, array<string|int, mixed> $types) : void
Parameters
$params : array<string|int, mixed>

list of values to be bound

$types : array<string|int, mixed>

list of types to be used, keys should match those in $params

Tags
inheritDoc

bindValue()

Assign a value to a positional or named variable in prepared query. If using positional variables you need to start with index one, if using named params then just use the name in any order.

public bindValue(mixed $column, mixed $value[, mixed $type = 'string' ]) : void
Parameters
$column : mixed

name or param position to be bound

$value : mixed

The value to bind to variable in query

$type : mixed = 'string'

name of configured Type class, or PDO type constant.

Tags
inheritDoc

cast()

Converts a give value to a suitable database value based on type and return relevant internal statement type

public cast(mixed $value[, TypeInterface|string|int $type = 'string' ]) : array<string|int, mixed>
Parameters
$value : mixed

The value to cast

$type : TypeInterface|string|int = 'string'

The type name or type instance to use.

Tags
pslam-return

array{mixed, int}

Return values
array<string|int, mixed>

list containing converted value and internal type

closeCursor()

Closes a cursor in the database, freeing up any resources and memory allocated to it. In most cases you don't need to call this method, as it is automatically called after fetching all results from the result set.

public closeCursor() : void
Tags
inheritDoc

columnCount()

Returns the number of columns this statement's results will contain

public columnCount() : int
Tags
inheritDoc
Return values
int

count()

Statements can be passed as argument for count() to return the number for affected rows from last execution.

public count() : int
Return values
int

current()

Returns the current record in the iterator

public current() : mixed
Attributes
#[ReturnTypeWillChange]

errorCode()

Returns the error code for the last error that occurred when executing this statement

public errorCode() : string|int
Tags
inheritDoc
Return values
string|int

errorInfo()

Returns the error information for the last error that occurred when executing this statement

public errorInfo() : array<string|int, mixed>
Tags
inheritDoc
Return values
array<string|int, mixed>

execute()

Executes the statement by sending the SQL query to the database. It can optionally take an array or arguments to be bound to the query variables. Please note that binding parameters from this method will not perform any custom type conversion as it would normally happen when calling `bindValue`

public execute([array<string|int, mixed>|null $params = null ]) : bool
Parameters
$params : array<string|int, mixed>|null = null

list of values to be bound to query

Tags
inheritDoc
Return values
bool

true on success, false otherwise

fetch()

Returns the next row for the result set after executing this statement.

public fetch([string|int $type = self::FETCH_TYPE_NUM ]) : array<string|int, mixed>|false
Parameters
$type : string|int = self::FETCH_TYPE_NUM

The type to fetch.

Return values
array<string|int, mixed>|false

fetchAll()

Returns an array with all rows resulting from executing this statement

public fetchAll([mixed $type = self::FETCH_TYPE_NUM ]) : array<string|int, mixed>|false
Parameters
$type : mixed = self::FETCH_TYPE_NUM

num for fetching columns as positional keys or assoc for column names as keys

Tags
inheritDoc
Return values
array<string|int, mixed>|false

list of all results from database for this statement or false on failure.

fetchAssoc()

public fetchAssoc() : array<string|int, mixed>
Return values
array<string|int, mixed>

fetchColumn()

Returns the value of the result at position.

public fetchColumn(int $position) : mixed
Parameters
$position : int

The numeric position of the column to retrieve in the result

Tags
inheritDoc
Return values
mixed

Returns the specific value of the column designated at $position

key()

Returns the current key in the iterator

public key() : mixed
Attributes
#[ReturnTypeWillChange]

lastInsertId()

Returns the latest primary inserted using this statement

public lastInsertId([string|null $table = null ][, string|null $column = null ]) : string|int
Parameters
$table : string|null = null

table name or sequence to get last insert value from

$column : string|null = null

the name of the column representing the primary key

Tags
inheritDoc
Return values
string|int

matchTypes()

Matches columns to corresponding types

public matchTypes(array<string|int, mixed> $columns, array<string|int, mixed> $types) : array<string|int, mixed>

Both $columns and $types should either be numeric based or string key based at the same time.

Parameters
$columns : array<string|int, mixed>

list or associative array of columns and parameters to be bound with types

$types : array<string|int, mixed>

list or associative array of types

Return values
array<string|int, mixed>

next()

Advances the iterator pointer to the next element

public next() : void

rowCount()

Returns the number of rows affected by this SQL statement

public rowCount() : int
Tags
inheritDoc
Return values
int

valid()

Returns whether the iterator has more elements

public valid() : bool
Return values
bool

        
On this page

Search results