Connection
class Connection
Manages database connection and executes SQL queries.
Properties
| $onConnect | |||
| $onQuery |
Methods
No description
Connects to the database server if not already connected.
Disconnects and connects to database again.
Disconnects from database.
No description
No description
Sets a callback for normalizing each result row (e.g., type conversion). Pass null to disable.
Returns the ID of the last inserted row, or the last value from a sequence.
Quotes string for use in SQL.
Starts a transaction.
Commits current transaction.
Rolls back current transaction.
Executes callback inside a transaction. Supports nesting.
Preprocesses SQL query with parameter substitution and returns the resulting SQL and bound parameters.
No description
Executes SQL query and returns the first row, or null if no rows were returned.
Executes SQL query and returns the first row as an associative array, or null.
Executes SQL query and returns the first field of the first row, or null.
Executes SQL query and returns the first row as an indexed array, or null.
Executes SQL query and returns the first row as an indexed array, or null.
No description
Executes SQL query and returns all rows as an array of Row objects.
Creates SQL literal value.
Details
at line 39
__construct(string $dsn, string|null $user = null, string|null $password = null, array $options = [])
No description
at line 60
void
connect()
Connects to the database server if not already connected.
at line 89
void
reconnect()
Disconnects and connects to database again.
at line 99
void
disconnect()
Disconnects from database.
at line 105
string
getDsn()
No description
at line 111
PDO
getPdo()
No description
at line 118
Driver
getDriver()
No description
at line 126
Driver
getSupplementalDriver()
deprecated
deprecated
No description
at line 133
Reflection
getReflection()
No description
at line 143
Connection
setRowNormalizer(callable|null $normalizer)
Sets a callback for normalizing each result row (e.g., type conversion). Pass null to disable.
at line 153
string
getInsertId(string|null $sequence = null)
Returns the ID of the last inserted row, or the last value from a sequence.
at line 167
string
quote(string $string, int $type = PDO::PARAM_STR)
Quotes string for use in SQL.
at line 181
void
beginTransaction()
Starts a transaction.
at line 195
void
commit()
Commits current transaction.
at line 209
void
rollBack()
Rolls back current transaction.
at line 223
mixed
transaction(callable $callback)
Executes callback inside a transaction. Supports nesting.
at line 254
ResultSet
query(string $sql, mixed ...$params)
Generates and executes SQL query.
at line 274
ResultSet
queryArgs(string $sql, array $params)
deprecated
deprecated
No description
at line 285
array
preprocess(string $sql, mixed ...$params)
Preprocesses SQL query with parameter substitution and returns the resulting SQL and bound parameters.
at line 294
string|null
getLastQueryString()
No description
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.
at line 318
array|null
fetchAssoc(string $sql, mixed ...$params)
Executes SQL query and returns the first row as an associative array, or null.
at line 328
mixed
fetchField(string $sql, mixed ...$params)
Executes SQL query and returns the first field of the first row, or null.
at line 339
array|null
fetchList(string $sql, mixed ...$params)
Executes SQL query and returns the first row as an indexed array, or 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.
at line 361
array
fetchPairs(string $sql, mixed ...$params)
No description
at line 372
array
fetchAll(string $sql, mixed ...$params)
Executes SQL query and returns all rows as an array of Row objects.
at line 381
static SqlLiteral
literal(string $value, mixed ...$params)
Creates SQL literal value.