flyokai/laminas-db

Database abstraction layer, SQL abstraction, result set abstraction, and RowDataGateway and TableDataGateway implementations

Maintainers

Package info

github.com/flyokai/laminas-db

Homepage

Issues

Chat

Forum

Documentation

pkg:composer/flyokai/laminas-db

Statistics

Installs: 9

Dependents: 3

Suggesters: 0

Stars: 0

v1.0.0 2026-06-04 07:39 UTC

README

User docs → README.md · Agent quick-ref → CLAUDE.md · Agent deep dive → AGENTS.md

Database abstraction layer for the Flyokai framework — fork of laminas/laminas-db.

Provides the synchronous foundation: adapters, drivers, SQL builders, table gateways, and platform-specific dialect generation. Async behaviour is added on top by sibling packages — this fork keeps the upstream API intact.

Use flyokai/laminas-db-driver-amp (native AMPHP MySQL) or flyokai/laminas-db-driver-async (PDO/MySQLi worker pools) on top of this package for non-blocking I/O.

Features

  • Adapters & drivers — Pdo, Mysqli, Pgsql, Oci8, IbmDb2, Sqlsrv
  • SQL buildersSelect, Insert, Update, Delete with fluent, platform-agnostic API
  • Platform abstraction — Mysql, Postgresql, Oracle, SqlServer, Sqlite, IbmDb2, Sql92
  • Predicate system — Between, EqualTo, In, IsNull, Like, …
  • TableGatewayselect(), insert(), update(), delete() with a feature/plugin system
  • Result sets — buffered or forward-only
  • Metadata — schema introspection (MysqlMetadata, PostgresqlMetadata, …)

Installation

composer require laminas/laminas-db

Composer's replace makes this fork resolve under the upstream name automatically inside Flyokai installs.

Quick start

use Laminas\Db\Adapter\Adapter;
use Laminas\Db\Sql\Sql;

$adapter = new Adapter([
    'driver'   => 'Pdo_Mysql',
    'database' => 'app',
    'username' => 'app',
    'password' => 'secret',
    'hostname' => 'localhost',
]);

$sql    = new Sql($adapter);
$select = $sql->select('users')
              ->where(['status' => 'active'])
              ->order('created DESC')
              ->limit(20);

$stmt = $sql->prepareStatementForSqlObject($select);
$rows = iterator_to_array($stmt->execute());

Adapter

Coordinates driver + platform + query execution.

  • Query modes: QUERY_MODE_PREPARE (parameterised) / QUERY_MODE_EXECUTE (direct)
  • ProfilerInterface support for query profiling
  • Factory methods: createStatement(), createDriver(), createPlatform()

SQL builders

use Laminas\Db\Sql\Sql;

$sql    = new Sql($adapter);

$insert = $sql->insert('users')
    ->columns(['email', 'name'])
    ->values(['a@b.com', 'Alice']);

$update = $sql->update('users')
    ->set(['status' => 'disabled'])
    ->where(['email' => 'a@b.com']);

$delete = $sql->delete('users')->where(['email' => 'a@b.com']);

Sql::buildSqlString($sqlObject) generates platform-aware SQL; Sql::prepareStatementForSqlObject($sqlObject) returns a prepared statement.

TableGateway

use Laminas\Db\TableGateway\TableGateway;

$users = new TableGateway('users', $adapter);

$users->insert(['email' => 'a@b.com', 'name' => 'Alice']);
$rows = $users->select(['status' => 'active']);
$users->update(['status' => 'inactive'], ['id' => 7]);
$users->delete(['id' => 7]);

A FeatureSet plugs in pre/post operation hooks (e.g. metadata introspection, hydrator-based mapping).

Async integration points

Async packages extend this foundation by:

  1. Implementing DriverInterface / ConnectionInterface non-blockingly.
  2. Wrapping Statement::execute() and Connection::execute() for fiber suspension.
  3. Using the Feature system in TableGateway for async lifecycle hooks.

See flyokai/laminas-db-driver-amp and flyokai/laminas-db-driver-async.

Gotchas

  • Empty WHERE protectionUpdate and Delete have $emptyWhereProtection = true by default. They refuse to run without a WHERE clause to prevent full-table operations.
  • Forward-only results — default is streaming. Call buffer() on the result set to enable re-iteration.
  • Platform abstraction — SQL objects don't generate SQL directly; that's delegated to platform classes via Sql::buildSqlString().
  • Parameter naming — driver-specific (PostgreSQL $1, $2 vs MySQL ?). Use ParameterContainer for binding.
  • No async in this package — use the driver-* siblings.

License

BSD-3-Clause — Copyright (c) Laminas Project. See LICENSE.md.

See also