Interface StatementInterface
Constants
Method Summary
-
bind() public
Binds a set of values to statement object with corresponding type.
-
bindValue() public
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.
-
closeCursor() public
Closes the cursor, enabling the statement to be executed again.
-
columnCount() public
Returns the number of columns in the result set.
-
errorCode() public
Fetch the SQLSTATE associated with the last operation on the statement handle.
-
errorInfo() public
Fetch extended error information associated with the last operation on the statement handle.
-
execute() public
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() public
Fetches the next row from a result set and converts fields to types based on TypeMap.
-
fetchAll() public
Fetches the remaining rows from a result set and converts fields to types based on TypeMap.
-
fetchAssoc() public
Fetches the next row from a result set using PDO::FETCH_ASSOC and converts fields to types based on TypeMap.
-
fetchColumn() public
Fetches the next row from a result set using PDO::FETCH_NUM and converts fields to types based on TypeMap.
-
getBoundParams() public
Get the bound params.
-
lastInsertId() public
Returns the latest primary inserted using this statement.
-
queryString() public
Returns prepared query string.
-
rowCount() public
Returns the number of rows affected by the last SQL statement.
Method Detail
bind() ¶ public
bind(array $params, array $types): void
Binds a set of values to statement object with corresponding type.
Parameters
-
array
$params list of values to be bound
-
array
$types list of types to be used, keys should match those in $params
Returns
void
bindValue() ¶ public
bindValue(string|int $column, mixed $value, string|int|null $type = 'string'): 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.
It is not allowed to combine positional and named variables in the same statement.
Examples:
$statement->bindValue(1, 'a title');
$statement->bindValue('active', true, 'boolean');
$statement->bindValue(5, new \DateTime(), 'date');
Parameters
-
string|int
$column name or param position to be bound
-
mixed
$value The value to bind to variable in query
-
string|int|null
$type optional name of configured Type class
Returns
void
closeCursor() ¶ public
closeCursor(): void
Closes the cursor, enabling the statement to be executed again.
This behaves the same as PDOStatement::closeCursor()
.
Returns
void
columnCount() ¶ public
columnCount(): int
Returns the number of columns in the result set.
This behaves the same as PDOStatement::columnCount()
.
Returns
int
Links
errorCode() ¶ public
errorCode(): string
Fetch the SQLSTATE associated with the last operation on the statement handle.
This behaves the same as PDOStatement::errorCode()
.
Returns
string
Links
errorInfo() ¶ public
errorInfo(): array
Fetch extended error information associated with the last operation on the statement handle.
This behaves the same as PDOStatement::errorInfo()
.
Returns
array
Links
execute() ¶ public
execute(array|null $params = null): 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
.
Parameters
-
array|null
$params optional list of values to be bound to query
Returns
bool
fetch() ¶ public
fetch(string|int $mode = PDO::FETCH_NUM): mixed
Fetches the next row from a result set and converts fields to types based on TypeMap.
This behaves the same as PDOStatement::fetch()
.
Parameters
-
string|int
$mode optional PDO::FETCH_* constant or fetch mode name. Valid names are 'assoc', 'num' or 'obj'.
Returns
mixed
Throws
InvalidArgumentException
Links
fetchAll() ¶ public
fetchAll(string|int $mode = PDO::FETCH_NUM): array
Fetches the remaining rows from a result set and converts fields to types based on TypeMap.
This behaves the same as PDOStatement::fetchAll()
.
Parameters
-
string|int
$mode optional PDO::FETCH_* constant or fetch mode name. Valid names are 'assoc', 'num' or 'obj'.
Returns
array
Throws
InvalidArgumentException
Links
fetchAssoc() ¶ public
fetchAssoc(): array
Fetches the next row from a result set using PDO::FETCH_ASSOC and converts fields to types based on TypeMap.
This behaves the same as PDOStatement::fetch()
except an
empty array is returned instead of false.
Returns
array
fetchColumn() ¶ public
fetchColumn(int $position): mixed
Fetches the next row from a result set using PDO::FETCH_NUM and converts fields to types based on TypeMap.
This behaves the same as PDOStatement::fetch()
except only
a specific column from the row is returned.
Parameters
-
int
$position Column index in result row.
Returns
mixed
lastInsertId() ¶ public
lastInsertId(string|null $table = null, string|null $column = null): string|int
Returns the latest primary inserted using this statement.
Parameters
-
string|null
$table optional table name or sequence to get last insert value from
-
string|null
$column optional the name of the column representing the primary key
Returns
string|int
rowCount() ¶ public
rowCount(): int
Returns the number of rows affected by the last SQL statement.
This behaves the same as PDOStatement::rowCount()
.
Returns
int