PDO
PDO
Trait providing base PDO operations for relational database drivers.
trait PDOIncludes methods for executing queries, preparing statements, quoting values, managing attributes, and handling connection state.
Properties
public $lastQueryString
Stores the last SQL query string executed or prepared.
private string $lastQueryStringMethods
exec
Executes an SQL statement and returns the number of affected rows or false on failure.
public exec(string $sql): intParameters
| Parameter | Type | Description |
|---|---|---|
$sql | string | the SQL statement to execute |
prepare
Prepares an SQL statement for execution.
public prepare(string $sql): StatementParameters
| Parameter | Type | Description |
|---|---|---|
$sql | string | the SQL statement to prepare |
prepareQuery
Prepares a query using a QueryBuilder instance and sets the last query string.
public prepareQuery(QueryBuilder $queryBuilder): StatementParameters
| Parameter | Type | Description |
|---|---|---|
$queryBuilder | QueryBuilder | the query builder instance |
lastQueryString
Returns the last SQL query string executed or prepared.
public lastQueryString(): stringquery
public query(string $sql, array $parameters): ResultParameters
| Parameter | Type | Description |
|---|---|---|
$sql | string | |
$parameters | array |
quote
Quotes a string for use in an SQL statement, using the current PDO connection.
public quote(mixed $string, int $type = '\PDO::PARAM_STR'): stringParameters
| Parameter | Type | Description |
|---|---|---|
$string | mixed | the string to quote |
$type | int | the data type for parameter binding (default: \PDO::PARAM_STR) |
setTimezone
Sets the timezone for the database connection. (Not implemented for PDO.).
public setTimezone(string $tz): boolParameters
| Parameter | Type | Description |
|---|---|---|
$tz | string | the timezone identifier |
lastInsertId
Returns the ID of the last inserted row.
public lastInsertId(): stringgetAttribute
Retrieves the value of a PDO attribute.
public getAttribute(int $attribute): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$attribute | int | the attribute identifier |
setAttribute
Sets the value of a PDO attribute.
public setAttribute(int $attribute, mixed $value): boolParameters
| Parameter | Type | Description |
|---|---|---|
$attribute | int | the attribute identifier |
$value | mixed | the value to set for the attribute |
errorInfo
public errorInfo(): voiderrorCode
Returns the error code for the last PDO operation.
public errorCode(): stringconnect
protected connect(string $dsn, ?string $username, ?string $password, ?array $driverOptions): boolParameters
| Parameter | Type | Description |
|---|---|---|
$dsn | string | |
$username | string | |
$password | string | |
$driverOptions | array |
mkdsn
protected mkdsn(array $config): stringParameters
| Parameter | Type | Description |
|---|---|---|
$config | array |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:24 +0000