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.
Drivers don't connect when they are constructed. connect() opens the connection, and returns false rather than throwing if it can't, so a caller can carry on (e.g. to create a missing database) and try again (#639). Anything that needs the connection before then throws NotConnected.
Properties
pdo
public \PDO $pdoType: PDO
connectionError
public \PDOException $connectionErrorType: PDOException
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
Opens the database connection, if it isn't already open.
public connect(): boolReturns: bool
disconnect
Closes the database connection.
public disconnect(): voidReturns: void
isConnected
Returns true if the database connection is open.
public isConnected(): boolReturns: bool
getConnectionError
Returns why the last connect() attempt failed, or null if it didn't.
public getConnectionError(): ?\PDOExceptionReturns: PDOException
pdo
Returns the PDO connection.
protected pdo(): \PDOReturns: PDO
getConnectionParams
protected getConnectionParams(): arrayReturns: array
initialiseConnection
Configures a newly opened connection. Drivers override this for session settings.
protected initialiseConnection(): voidReturns: void
mkdsn
protected mkdsn(array $config): false|stringReturns: false|string
Parameters
| Parameter | Type | Description |
|---|---|---|
$config | array |
Generated by Hazaar API Doc Generator on Sun, 08 Nov 2026 03:36:14 +0000