Download the PHP package hectororm/connection without Composer
On this page you can find all versions of the php package hectororm/connection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hectororm/connection
More information about hectororm/connection
Files in hectororm/connection
Package connection
Short Description Hector Connection
License MIT
Homepage https://gethectororm.com
Informations about the package connection
Hector Connection
Hector Connection is the PDO connection module of Hector ORM. Can be used independently of ORM.
Installation
Composer
You can install Hector Connection with Composer, it's the recommended installation.
Dependencies
- PHP ^8.0
- PHP extensions:
- PDO
Usage
Create a connection
The connection information must be pass to DSN format, with password inside.
To create a simple connection:
You can create a complex connection with read/write ways:
Query
Execute
Execute a statement and get the number of affected rows.
The method execute queries on write DSN.
Fetch
Three methods are available to fetch results. When multiple results, methods returns a Generator
.
You can pass parameters for statement to the second argument of methods.
All fetch methods are done on read DSN.
Fetch one
Fetch one result from statement.
NULL
returned if no result.
Fetch all
Fetch all result from statement.
Fetch column
Fetch only one column of all result from statement.
Last insert ID
You can retrieve the last insert ID with method getLastInsertId()
.
Transactions
Connection
class has 4 methods to play with transactions:
Connection::beginTransaction(): void
Connection::commit(): void
Connection::rollBack(): void
Connection::inTransaction(): bool
If you begin a new transaction even though a transaction has already started, the new transaction will be ignored, and
it needed to call even times the commit
or rollBack
methods.
Connection set
You can create a set of Connection
objects with ConnectionSet
class.
It needed to name different connections, the default name is store in constant Connection::DEFAULT_NAME
.
Logger
A logger is available to log queries.