PHPackages                             flyokai/laminas-db-driver-amp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. flyokai/laminas-db-driver-amp

ActiveLibrary[Database &amp; ORM](/categories/database)

flyokai/laminas-db-driver-amp
=============================

Amphp driver for laminas db

0.1.0(1mo ago)02↓100%MITPHPPHP ^8.1

Since Apr 25Pushed 2w agoCompare

[ Source](https://github.com/flyokai/laminas-db-driver-amp)[ Packagist](https://packagist.org/packages/flyokai/laminas-db-driver-amp)[ RSS](/packages/flyokai-laminas-db-driver-amp/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

flyokai/laminas-db-driver-amp
=============================

[](#flyokailaminas-db-driver-amp)

> User docs → [`README.md`](README.md) · Agent quick-ref → [`CLAUDE.md`](CLAUDE.md) · Agent deep dive → [`AGENTS.md`](AGENTS.md)

> Native AMPHP MySQL driver for Laminas DB — non-blocking queries via `amphp/mysql` with fiber-aware connection pooling and transaction nesting.

Plugs the pure-PHP `amphp/mysql` client into Laminas DB. Every query suspends the current fiber rather than blocking the thread.

Features
--------

[](#features)

- **`AmpDriver`** — Laminas-DB-compatible driver implementing `DriverInterface`, `DriverFeatureInterface`, `ProfilerAwareInterface`
- **Named parameters** — `:param_name` placeholders
- **Fiber-local state** — transaction level, last-insert-id, rollback flag, current transaction
- **Transaction nesting** — outer commit only, nested rollbacks invalidate the outer commit
- **Custom MySQL platform** — value quoting (unquoted ints, escaped strings)
- **`InitConnector`** — runs `SET SQL_MODE=''` and `SET time_zone='+00:00'` on every fresh connection

Installation
------------

[](#installation)

```
composer require flyokai/laminas-db-driver-amp
```

Quick start
-----------

[](#quick-start)

```
use Amp\Mysql\MysqlConfig;
use Amp\Mysql\MysqlConnectionPool;
use Flyokai\LaminasDbDriverAmp\AmpDriver;
use Flyokai\LaminasDbDriverAmp\Connection;
use Laminas\Db\Adapter\Adapter;

$config = MysqlConfig::fromString('host=localhost user=root password=pw db=app');
$pool   = new MysqlConnectionPool(null, config: $config);

$connection = new Connection($pool);
$driver     = new AmpDriver($connection);

$adapter = new Adapter($driver);

// Use the adapter exactly like a synchronous Laminas adapter — every call is async.
$rows = $adapter->query('SELECT * FROM users WHERE status = :status', ['status' => 'active'])
    ->getResource();
```

Components
----------

[](#components)

ClassRole`AmpDriver`Entry point. Creates `Statement` / `Result` objects via prototype cloning. Returns `PARAMETERIZATION_NAMED`.`Connection`Wraps `MysqlConnectionPool`. FiberLocal transaction state.`Statement`Wraps `MysqlStatement`. Lazy preparation, named params.`Result`Forward-only iterator over `MysqlResultWrapper`.`MysqlResultWrapper`PDO-like façade — `fetch()`, `fetchAll()`, `fetchColumn()`, `rowCount()``Platform\Mysql`Custom value quoting`InitConnector`Wraps `SqlConnector` to run init SQL on every new connection`mysqlConnector(...)`Cached connector factory keyed by EventLoop driver### Transaction nesting

[](#transaction-nesting)

```
$connection->beginTransaction();   // level 0 → 1, MysqlTransaction created
$connection->beginTransaction();   // level 1 → 2 (no DB call)
$connection->commit();             // level 2 → 1 (no DB call)
$connection->commit();             // level 1 → 0, real COMMIT

// Nested rollback:
$connection->beginTransaction();
$connection->beginTransaction();
$connection->rollBack();           // sets isRolledBack=true
$connection->commit();             // throws — outer commit refused after nested rollback
```

### Fiber-local state

[](#fiber-local-state)

When `fiber_mode=true` (default), these are `FiberLocal`:

- `$transactionLevel` — nesting counter
- `$lastInsertId` — last insert id
- `$isRolledBack` — rollback flag
- `$currentTransaction` — active `MysqlTransaction`

Each fiber sees its own values so concurrent fibers don't trample each other's transaction state.

### `InitConnector`

[](#initconnector)

```
new InitConnector($baseConnector, [
    "SET SQL_MODE=''",
    "SET time_zone='+00:00'",
    // your custom init statements
]);
```

Defaults: `SET SQL_MODE=''` and `SET time_zone='+00:00'`.

Gotchas
-------

[](#gotchas)

- **Forward-only results** — cannot rewind after iterating. Use `fetchAll()` to buffer into an array if you need to re-read.
- **Fiber mode requires a fiber** — `fiber_mode=true` (default) requires Fiber/EventLoop context. `FiberLocal` fails outside fibers.
- **Pool is required** — `Connection` does not auto-create a pool; pass it via `setPool()` or `connection_pool` parameter.
- **Statement clone resets prep** — cloned statements re-prepare on next execute.
- **`InitConnector` clears `SQL_MODE`** — hard-coded `SET SQL_MODE=''`. May mask data issues in production.
- **No multi-result-set iteration** — `getNextResult()` exists but the `Result` iterator does not auto-advance.
- **Transaction rollback requires manual cleanup** — nested `rollBack()` sets a flag; outer `commit()` throws if the flag is set.
- **Requires active EventLoop** — every operation suspends via Revolt.

See also
--------

[](#see-also)

- [`flyokai/laminas-db`](../laminas-db/README.md) — base DB abstraction
- [`flyokai/laminas-db-driver-async`](../laminas-db-driver-async/README.md) — alternative strategy via worker pools

License
-------

[](#license)

MIT

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance94

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

45d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/247743048?v=4)[flyokai](/maintainers/flyokai)[@flyokai](https://github.com/flyokai)

---

Top Contributors

[![flyokai](https://avatars.githubusercontent.com/u/247743048?v=4)](https://github.com/flyokai "flyokai (3 commits)")

### Embed Badge

![Health badge](/badges/flyokai-laminas-db-driver-amp/health.svg)

```
[![Health](https://phpackages.com/badges/flyokai-laminas-db-driver-amp/health.svg)](https://phpackages.com/packages/flyokai-laminas-db-driver-amp)
```

###  Alternatives

[danog/madelineproto

Async PHP client API for the telegram MTProto protocol.

3.4k885.1k21](/packages/danog-madelineproto)[phpro/grumphp

A composer plugin that enables source code quality checks.

4.3k16.3M972](/packages/phpro-grumphp)[amphp/mysql

Asynchronous MySQL client for PHP based on Amp.

3761.1M33](/packages/amphp-mysql)[amphp/postgres

Asynchronous PostgreSQL client for Amp.

110557.2k35](/packages/amphp-postgres)[amphp/sql

Asynchronous SQL client for Amp.

201.3M14](/packages/amphp-sql)[amphp/sql-common

Common classes for non-blocking SQL implementations.

131.3M7](/packages/amphp-sql-common)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
