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
pdo
The underlying PDO instance used for database operations.
protected \PDO $pdoType: PDO
lastQueryString
Stores the last SQL query string executed or prepared.
private string $lastQueryStringType: string
Methods
exec
Executes an SQL statement and returns the number of affected rows or false on failure.
public exec(string $sql): false|intReturns: false|int
Parameters
| Parameter | Type | Description |
|---|---|---|
$sql | string | the SQL statement to execute |
prepare
Prepares an SQL statement for execution.
public prepare(string $sql): false|StatementReturns: false|Hazaar\DBI\Statement
Parameters
| 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): false|StatementReturns: false|Hazaar\DBI\Statement
Parameters
| Parameter | Type | Description |
|---|---|---|
$queryBuilder | Hazaar\DBI\Interface\QueryBuilder | the query builder instance |
lastQueryString
Returns the last SQL query string executed or prepared.
public lastQueryString(): stringReturns: string
query
public query(string $sql, array $parameters): false|ResultReturns: false|Hazaar\DBI\Result
Parameters
| Parameter | Type | Description |
|---|---|---|
$sql | string | |
$parameters | array |
quote
Quotes a string for use in an SQL statement, using the current PDO connection.
public quote(string $string, int $type = '\PDO::PARAM_STR'): false|stringReturns: false|string
Parameters
| Parameter | Type | Description |
|---|---|---|
$string | string | 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): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$tz | string | the timezone identifier |
lastInsertId
Returns the ID of the last inserted row.
public lastInsertId(): stringReturns: string
getAttribute
Retrieves the value of a PDO attribute.
public getAttribute(int $attribute): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$attribute | int | the attribute identifier |
setAttribute
Sets the value of a PDO attribute.
public setAttribute(int $attribute, mixed $value): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$attribute | int | the attribute identifier |
$value | mixed | the value to set for the attribute |
errorInfo
public errorInfo(): arrayReturns: array
errorCode
Returns the error code for the last PDO operation.
public errorCode(): stringReturns: string
connect
protected connect(string $dsn, ?string $username, ?string $password, ?array $driverOptions): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$dsn | string | |
$username | string | |
$password | string | |
$driverOptions | array |
mkdsn
protected mkdsn(array $config): false|stringReturns: false|string
Parameters
| Parameter | Type | Description |
|---|---|---|
$config | array |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000