Class SqlserverStatement
Statement class meant to be used by an Sqlserver driver
Constants
-
string
FETCH_TYPE_ASSOC ¶'assoc'
Maps to PDO::FETCH_ASSOC.
-
string
FETCH_TYPE_NUM ¶'num'
Maps to PDO::FETCH_NUM.
-
string
FETCH_TYPE_OBJ ¶'obj'
Maps to PDO::FETCH_OBJ.
-
array<string, int>
MODE_NAME_MAP ¶[self::FETCH_TYPE_ASSOC => PDO::FETCH_ASSOC, self::FETCH_TYPE_NUM => PDO::FETCH_NUM, self::FETCH_TYPE_OBJ => PDO::FETCH_OBJ]
Property Summary
-
$_driver protected
Cake\Database\Driver
-
$params protected
array<mixed>
Cached bound parameters used for logging
-
$statement protected
PDOStatement
-
$typeConverter protected
Cake\Database\FieldTypeConverter|null
Method Summary
-
__construct() public
-
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.
-
cast() protected
Converts a give value to a suitable database value based on type and return relevant internal statement type.
-
closeCursor() public
Closes the cursor, enabling the statement to be executed again.
-
columnCount() public
Returns the number of columns in the result set.
-
convertMode() protected
Converts mode name to PDO constant.
-
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.
-
performBind() protected
-
queryString() public
Returns prepared query string stored in PDOStatement.
-
rowCount() public
Returns the number of rows affected by the last SQL statement.
Method Detail
__construct() ¶ public
__construct(PDOStatement $statement, Cake\Database\Driver $driver, Cake\Database\TypeMap|null $typeMap = null)
Parameters
-
PDOStatement
$statement PDO statement
-
Cake\Database\Driver
$driver Database driver
-
Cake\Database\TypeMap|null
$typeMap optional Results type map
bind() ¶ public
bind(array $params, array $types): void
Binds a set of values to statement object with corresponding type.
Parameters
-
array
$params -
array
$types
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 -
mixed
$value -
string|int|null
$type optional
Returns
void
cast() ¶ protected
cast(mixed $value, Cake\Database\TypeInterface|string|int $type = 'string'): array
Converts a give value to a suitable database value based on type and return relevant internal statement type.
Parameters
-
mixed
$value The value to cast.
-
Cake\Database\TypeInterface|string|int
$type optional The type name or type instance to use.
Returns
array
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
convertMode() ¶ protected
convertMode(string|int $mode): int
Converts mode name to PDO constant.
Parameters
-
string|int
$mode Mode name or PDO constant
Returns
int
Throws
InvalidArgumentException
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
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
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
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
Returns
mixed
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
Returns
array
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
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 -
string|null
$column optional
Returns
string|int
performBind() ¶ protected
performBind(string|int $column, mixed $value, int $type): void
Parameters
-
string|int
$column -
mixed
$value -
int
$type
Returns
void
queryString() ¶ public
queryString(): string
Returns prepared query string stored in PDOStatement.
Returns
string
rowCount() ¶ public
rowCount(): int
Returns the number of rows affected by the last SQL statement.
This behaves the same as PDOStatement::rowCount()
.
Returns
int