Download the PHP package webservco/database without Composer
On this page you can find all versions of the php package webservco/database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webservco/database
More information about webservco/database
Files in webservco/database
Package database
Short Description A PHP component/library.
License MIT
Homepage https://webserv.co
Informations about the package database
webservco/database
A PHP component/library. Please see webservco/sandbox for an example project using these types of components.
PDO for MySQL and MariaDB, with a connection that opens on first use, query helpers and transactions.
- Requires:
ext-pdowith the MySQL driver, a MySQL or MariaDB server - Related:
webservco/data(to read typed values from result rows)
Installation
Usage
Create the container in a factory. The webservco/sandbox project does it in a module's local container factory, using values from the configuration.
Inject the container (not the PDO object) into storage classes and query through it:
Transactions
Contracts
| Interface | Implementation | Purpose |
|---|---|---|
Contract\PDOContainerInterface |
Container\PDOContainer |
getPDO() (shared, opened on first call), createPDO() (new connection), getPDOService(). |
Contract\PDOContainerFactoryInterface |
Factory\PDOContainerMySQLFactory |
Creates the container from connection details. |
Contract\PDOServiceInterface |
Service\PDOService |
Prepare, fetch, error info, last insert id, placeholders. |
Contract\TransactionalDatabaseServiceInterface |
Service\TransactionalDatabaseService |
Begin, commit (rolls back if the commit fails) and roll back. |
Contract\PDOFactoryInterface |
Factory\PDOFactory |
Creates a PDO object with the settings below. |
Namespaces are relative to WebServCo\Database\.
Configuration
The component takes plain values and doesn't care what the keys are called. The sandbox project uses:
Notes
Every connection uses utf8mb4, throws exceptions on errors, fetches associative arrays and uses real prepared statements (no emulation). Only the mysql driver is accepted.
Because the container opens the connection on first use, a long-running script doesn't hold an idle connection that the server may close ("MySQL server has gone away").
fetchAssoc() returns [] when there are no more rows. generatePlaceholdersString($values) returns ?,?,? for an IN (...) list. isRecoverableError() is true for a deadlock or a lock wait timeout. Retry those.
Development
License
MIT