CDO API
CDO extends PDO, adding the DML methods below. Everything else — query,
prepare, fetch*, transactions, attributes — is inherited from PDO unchanged.
Every method here throws CDOException on failure,
wrapping the original PDOException.
Identifiers are quoted; values are bound
Values are bound as prepared-statement parameters. Table and column names — which
cannot be bound — are quoted with the driver’s quoting characters ("…" for
PostgreSQL/Oracle, `…` for MySQL/MariaDB), so these DML methods are safe
even with dynamically built names. Because quoted identifiers are
case-sensitive in PostgreSQL, pass names exactly as they exist in the schema
(users, not Users). Note this quoting applies to the CDO methods only — column
names passed to Qb are not quoted.
Construction
You rarely construct CDO directly — ConnectionPool
does it for you. The constructor is:
public function __construct(
DbConfigInterface $config,
int $timeout = 5,
bool $debug = false
)| Parameter | Type | Default | Description |
|---|---|---|---|
config |
DbConfigInterface |
— | Connection config (credentials, driver, logger) |
timeout |
int |
5 |
Connection timeout in seconds (PDO::ATTR_TIMEOUT) |
debug |
bool |
false |
When true, sets PDO::ERRMODE_EXCEPTION |
getDriverName
public function getDriverName(): stringReturns the normalised driver: 'pgsql', 'mysql', 'mariadb', or 'oci'.
Unlike PDO::ATTR_DRIVER_NAME, this distinguishes MariaDB from MySQL — see
Driver detection.
insert
final public function insert(string $table, object|array $entity): mixedInserts one row and returns the generated primary key.
| Parameter | Type | Description |
|---|---|---|
table |
string |
Table name |
entity |
`object\ | array` |
- Returns the primary key — the value of the entity’s first key, read via
RETURNING(PostgreSQL/MariaDB) orlastInsertId()(MySQL). Returnsnullwhen there is no generated id to report. nullvalues inentityare excluded from theINSERT.- Throws
CDOExceptionon query failure.
insertGroup
final public function insertGroup(
string $table,
array $entities,
int $chunkSize = 1000
): voidBatch-inserts many rows as chunked multi-row INSERTs.
| Parameter | Type | Default | Description |
|---|---|---|---|
table |
string |
— | Table name |
entities |
array |
— | Array of arrays/objects |
chunkSize |
int |
1000 |
Rows per INSERT statement |
- Returns nothing. An empty
entitiesarray is a no-op. - Per-row
nullvalues are excluded. ThrowsCDOExceptionon failure.
upsert
final public function upsert(
string $table,
object|array $entity,
array $conflictColumns,
?array $updateColumns = null
): mixedInserts a row, or updates/ignores it on unique conflict.
| Parameter | Type | Default | Description |
|---|---|---|---|
table |
string |
— | Table name |
entity |
`object\ | array` | — |
conflictColumns |
array |
— | Column(s) defining uniqueness |
updateColumns |
`array\ | null` | null |
- Returns the primary key on PostgreSQL (via
RETURNING); on MySQL/MariaDB returnslastInsertId()(nullif no new row was inserted). - Throws
CDOExceptionifconflictColumnsis empty, or on query failure. - Expression tokens
:new/:current— see Upsert placeholders.
upsertGroup
final public function upsertGroup(
string $table,
array $entities,
array $conflictColumns,
?array $updateColumns = null,
int $chunkSize = 500
): voidBatch upsert with chunking.
| Parameter | Type | Default | Description |
|---|---|---|---|
table |
string |
— | Table name |
entities |
array |
— | Array of arrays/objects |
conflictColumns |
array |
— | Column(s) defining uniqueness |
updateColumns |
`array\ | null` | null |
chunkSize |
int |
500 |
Rows per statement |
- Returns nothing. Empty
entities⇒ no-op; emptyconflictColumns⇒ throws.
update
final public function update(string $table, object|array $entity, Qb $qb): intUpdates rows matching a Qb condition.
| Parameter | Type | Description |
|---|---|---|
table |
string |
Table name |
entity |
`object\ | array` |
qb |
Qb |
Condition for the WHERE clause |
- Returns the number of affected rows (
rowCount()). - Throws
CDOExceptionon failure.
delete
final public function delete(string $table, Qb $qb): intDeletes rows matching a Qb condition.
| Parameter | Type | Description |
|---|---|---|
table |
string |
Table name |
qb |
Qb |
Condition for the WHERE clause |
- Returns the number of deleted rows. Throws
CDOExceptionon failure.
applyDatabaseTimezone
public function applyDatabaseTimezone(mixed $driver, string $tz): voidSets the session timezone to match PHP’s. Called automatically at connect time; exposed as public so you can re-apply it after a driver-level reset. Behaviour per driver is documented in Driver detection.
Writes only; reads stay PDO
There is intentionally no select / find here. Read with the inherited PDO
methods and a Qb fragment for the WHERE.
Related
- Qb operators — building the
WHEREconditions - Configuration — configs, pool, statement, bind
- Exceptions — failure model and SQLSTATE codes