class Connection

Manages database connection and executes SQL queries.

Properties

$onConnect
$onQuery

Methods

__construct(string $dsn, string|null $user = null, string|null $password = null, array $options = [])

No description

void
connect()

Connects to the database server if not already connected.

void
reconnect()

Disconnects and connects to database again.

void
disconnect()

Disconnects from database.

string
getDsn()

No description

PDO
getPdo()

No description

getDriver()

No description

getSupplementalDriver() deprecated

No description

getReflection()

No description

setRowNormalizer(callable|null $normalizer)

Sets a callback for normalizing each result row (e.g., type conversion). Pass null to disable.

string
getInsertId(string|null $sequence = null)

Returns the ID of the last inserted row, or the last value from a sequence.

string
quote(string $string, int $type = PDO::PARAM_STR)

Quotes string for use in SQL.

void
beginTransaction()

Starts a transaction.

void
commit()

Commits current transaction.

void
rollBack()

Rolls back current transaction.

mixed
transaction(callable $callback)

Executes callback inside a transaction. Supports nesting.

query(string $sql, mixed ...$params)

Generates and executes SQL query.

queryArgs(string $sql, array $params) deprecated

No description

array
preprocess(string $sql, mixed ...$params)

Preprocesses SQL query with parameter substitution and returns the resulting SQL and bound parameters.

string|null
getLastQueryString()

No description

Row|null
fetch(string $sql, mixed ...$params)

Executes SQL query and returns the first row, or null if no rows were returned.

array|null
fetchAssoc(string $sql, mixed ...$params)

Executes SQL query and returns the first row as an associative array, or null.

mixed
fetchField(string $sql, mixed ...$params)

Executes SQL query and returns the first field of the first row, or null.

array|null
fetchList(string $sql, mixed ...$params)

Executes SQL query and returns the first row as an indexed array, or null.

array|null
fetchFields(string $sql, mixed ...$params)

Executes SQL query and returns the first row as an indexed array, or null.

array
fetchPairs(string $sql, mixed ...$params)

No description

array
fetchAll(string $sql, mixed ...$params)

Executes SQL query and returns all rows as an array of Row objects.

static SqlLiteral
literal(string $value, mixed ...$params)

Creates SQL literal value.

Details

at line 39
__construct(string $dsn, string|null $user = null, string|null $password = null, array $options = [])

No description

Parameters

string $dsn
string|null $user
string|null $password
array $options

at line 60
void connect()

Connects to the database server if not already connected.

Return Value

void

Exceptions

ConnectionException

at line 89
void reconnect()

Disconnects and connects to database again.

Return Value

void

at line 99
void disconnect()

Disconnects from database.

Return Value

void

at line 105
string getDsn()

No description

Return Value

string

at line 111
PDO getPdo()

No description

Return Value

PDO

at line 118
Driver getDriver()

No description

Return Value

Driver

at line 126
Driver getSupplementalDriver() deprecated

deprecated use getDriver()

No description

Return Value

Driver

at line 133
Reflection getReflection()

No description

Return Value

Reflection

at line 143
Connection setRowNormalizer(callable|null $normalizer)

Sets a callback for normalizing each result row (e.g., type conversion). Pass null to disable.

Parameters

callable|null $normalizer

Return Value

Connection

at line 153
string getInsertId(string|null $sequence = null)

Returns the ID of the last inserted row, or the last value from a sequence.

Parameters

string|null $sequence

Return Value

string

at line 167
string quote(string $string, int $type = PDO::PARAM_STR)

Quotes string for use in SQL.

Parameters

string $string
int $type

Return Value

string

at line 181
void beginTransaction()

Starts a transaction.

Return Value

void

Exceptions

LogicException

at line 195
void commit()

Commits current transaction.

Return Value

void

Exceptions

LogicException

at line 209
void rollBack()

Rolls back current transaction.

Return Value

void

Exceptions

LogicException

at line 223
mixed transaction(callable $callback)

Executes callback inside a transaction. Supports nesting.

Parameters

callable $callback

Return Value

mixed

at line 254
ResultSet query(string $sql, mixed ...$params)

Generates and executes SQL query.

Parameters

string $sql
mixed ...$params

Return Value

ResultSet

at line 274
ResultSet queryArgs(string $sql, array $params) deprecated

deprecated use query()

No description

Parameters

string $sql
array $params

Return Value

ResultSet

at line 285
array preprocess(string $sql, mixed ...$params)

Preprocesses SQL query with parameter substitution and returns the resulting SQL and bound parameters.

Parameters

string $sql
mixed ...$params

Return Value

array

at line 294
string|null getLastQueryString()

No description

Return Value

string|null

at line 307
Row|null fetch(string $sql, mixed ...$params)

Executes SQL query and returns the first row, or null if no rows were returned.

Parameters

string $sql
mixed ...$params

Return Value

Row|null

at line 318
array|null fetchAssoc(string $sql, mixed ...$params)

Executes SQL query and returns the first row as an associative array, or null.

Parameters

string $sql
mixed ...$params

Return Value

array|null

at line 328
mixed fetchField(string $sql, mixed ...$params)

Executes SQL query and returns the first field of the first row, or null.

Parameters

string $sql
mixed ...$params

Return Value

mixed

at line 339
array|null fetchList(string $sql, mixed ...$params)

Executes SQL query and returns the first row as an indexed array, or null.

Parameters

string $sql
mixed ...$params

Return Value

array|null

at line 350
array|null fetchFields(string $sql, mixed ...$params)

Executes SQL query and returns the first row as an indexed array, or null.

Parameters

string $sql
mixed ...$params

Return Value

array|null

at line 361
array fetchPairs(string $sql, mixed ...$params)

No description

Parameters

string $sql
mixed ...$params

Return Value

array

at line 372
array fetchAll(string $sql, mixed ...$params)

Executes SQL query and returns all rows as an array of Row objects.

Parameters

string $sql
mixed ...$params

Return Value

array

at line 381
static SqlLiteral literal(string $value, mixed ...$params)

Creates SQL literal value.

Parameters

string $value
mixed ...$params

Return Value

SqlLiteral