Configuration
Everything that describes and manages a connection: the config base classes and
their defaults, the inline Call constructors, the lifecycle methods shared by
all configs, the ConnectionPool registry, and the supporting CDOStatement and
CDOBind value types.
Config class hierarchy
DbConfigInterface
└── BaseDbConfig (abstract) — lifecycle, health checks, logger
├── PgDbConfig (abstract) — PostgreSQL defaults + schema/charset
├── MySqlDbConfig (abstract) — MySQL/MariaDB defaults + charset
├── DbConfig (abstract) — explicit $driver, no defaults
└── Config\Call\
├── PgDbCall — inline PostgreSQL (constructor args)
├── MySqlDbCall — inline MySQL/MariaDB (constructor args)
└── DbCall — inline generic (driver in constructor)Extend an abstract base and set credentials in setUp(); use a Call class
for a one-off connection without defining a subclass.
PgDbConfig
Extend for PostgreSQL. Properties and defaults:
| Property | Type | Default |
|---|---|---|
host |
string |
'localhost' |
port |
int |
5432 |
database |
string |
'postgres' |
username |
string |
'postgres' |
password |
string |
'' |
schema |
string |
'public' |
charset |
`string\ | null` |
getDriver() returns 'pgsql'. charset, when set, appends
options='--client_encoding=…' to the DSN. schema is returned by getSchema()
for higher layers that set search_path — CDO does not apply it automatically.
MySqlDbConfig
Extend for MySQL or MariaDB:
| Property | Type | Default |
|---|---|---|
host |
string |
'localhost' |
port |
int |
3306 |
database |
string |
'' |
username |
string |
'root' |
password |
string |
'' |
charset |
`string\ | null` |
getDriver() returns 'mysql'; MariaDB is detected at runtime (see
Driver detection). charset appends
charset=… to the DSN.
DbConfig
Driver-agnostic base — you set $this->driver yourself in setUp(), along with
host, port, database, username, password. No defaults are provided. Use
it when you need a driver that has no dedicated base.
Inline Call classes
Concrete configs that take everything in the constructor:
use Flytachi\Winter\Cdo\Config\Call\PgDbCall;
use Flytachi\Winter\Cdo\Config\Call\MySqlDbCall;
use Flytachi\Winter\Cdo\Config\Call\DbCall;
$pg = new PgDbCall(host: '127.0.0.1', database: 'myapp', username: 'postgres', password: 'secret');
$my = new MySqlDbCall(host: '127.0.0.1', database: 'myapp', username: 'root', password: 'secret', charset: 'utf8mb4');
$any = new DbCall(driver: 'mysql', host: '127.0.0.1', port: 3306, database: 'myapp', username: 'root', password: 'secret');
$cdo = $pg->connection();PgDbCall/MySqlDbCall— all args optional, falling back to the same defaults as their abstract counterparts.DbCall— all args required, includingdriver.
Connection lifecycle
Every config (via BaseDbConfig) exposes:
| Method | Returns | Description |
|---|---|---|
setUp() |
void |
Load credentials; called once by the pool |
connect(int $timeout = 3) |
void |
Open lazily (no-op if already open) |
connection() |
CDO |
Open if needed, return the CDO |
disconnect() |
void |
Release the CDO reference |
reconnect() |
void |
disconnect() then connect() |
ping() |
bool |
SELECT 1 reachability check |
pingDetail() |
array |
['status', 'latency', 'error'] |
getSchema() |
`string\ | null` |
getLogger() / setLogger() |
LoggerInterface / void |
PSR-3 logger access |
getDns() |
string |
The assembled PDO DSN |
Persistent connections are off by default; set protected bool $isPersistent = true
in a subclass to enable PDO::ATTR_PERSISTENT. Debug mode (PDO::ERRMODE_EXCEPTION)
is enabled when the DEBUG environment variable is truthy.
ConnectionPool
A process-level registry that instantiates each config once and hands back a ready connection.
| Method | Returns | Description |
|---|---|---|
db(string $className) |
CDO |
Resolve config + return live CDO |
getConfigDb(string $className, ?LoggerInterface $logger = null) |
DbConfigInterface |
Resolve (and cache) the config; optionally attach a logger on first instantiation |
showDbConfigs() |
DbConfigInterface[] |
All registered config instances |
$cdo = ConnectionPool::db(AppDb::class); // most common
$config = ConnectionPool::getConfigDb(AppDb::class); // for ping / reconnectThe $logger argument to getConfigDb() is applied only on the first call for
a given class; later calls return the cached instance and ignore it.
CDOStatement
A type-aware wrapper around PDOStatement, used internally by every DML method.
Its key method, bindTypedValue($param, $value), selects the PDO type from
gettype($value). Full type map in
Parameter binding.
| Method | Description |
|---|---|
bindTypedValue($param, $value) |
Bind with auto-detected PDO type |
bindValue($param, $value, $type = PDO::PARAM_STR) |
Bind with an explicit type; records it |
valObject(object $value) |
Serialise an object to a scalar (see binding page) |
getBindings() |
Recorded [param, value, type] triples |
updateStm(PDOStatement $stmt) |
Swap the statement and replay all binds |
getStmt() |
The wrapped PDOStatement (call execute/fetch* on it) |
CDOBind
An immutable name + value pair — the unit Qb produces for every scalar. Build
one by hand to name a placeholder or share it across conditions.
use Flytachi\Winter\Cdo\CDOBind;
$bind = new CDOBind('user_id', 42);
$bind->getName(); // ':user_id' (leading ':' added if omitted)
$bind->getValue(); // 42| Method | Returns |
|---|---|
getName() |
placeholder name, always :-prefixed |
getValue() |
the bound value (any PHP type the binder accepts) |
Related
- Installation — first config, step by step
- Logging & diagnostics — logger and health checks
- Parameter binding — how
CDOStatementtypes values - Building conditions —
CDOBindinQb