PHPackages                             initorm/dbal - 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. initorm/dbal

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

initorm/dbal
============

Lightweight PDO-based database abstraction layer with a fluent result mapper.

2.0.0(1mo ago)01281MITPHPPHP &gt;=8.0CI passing

Since Dec 9Pushed 3w agoCompare

[ Source](https://github.com/InitORM/DBAL)[ Packagist](https://packagist.org/packages/initorm/dbal)[ Docs](https://github.com/InitORM/DBAL)[ GitHub Sponsors](https://github.com/muhammetsafak)[ RSS](/packages/initorm-dbal/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (2)Versions (6)Used By (1)

InitORM DBAL
============

[](#initorm-dbal)

[![PHPUnit](https://github.com/InitORM/DBAL/actions/workflows/phpunit.yml/badge.svg)](https://github.com/InitORM/DBAL/actions/workflows/phpunit.yml)[![Latest Stable Version](https://camo.githubusercontent.com/5628b4da21c58af4dcc8f56311029b8539160674bccdaa51c2176ac88877cd28/68747470733a2f2f706f7365722e707567782e6f72672f696e69746f726d2f6462616c2f762f737461626c65)](https://packagist.org/packages/initorm/dbal)[![Total Downloads](https://camo.githubusercontent.com/787a2a8961bc2c073c9f51cbfae0065bc00c4c687153bdb4c25bb53caa7d5929/68747470733a2f2f706f7365722e707567782e6f72672f696e69746f726d2f6462616c2f646f776e6c6f616473)](https://packagist.org/packages/initorm/dbal)[![License](https://camo.githubusercontent.com/99b7afc4b78824e553132bb5c83513a53590b7966d58f059e2bdb86a849a97a0/68747470733a2f2f706f7365722e707567782e6f72672f696e69746f726d2f6462616c2f6c6963656e7365)](LICENSE)[![PHP Version Require](https://camo.githubusercontent.com/804ade03626702506463a88d7baf173bc17e19401ede069e160c4496c9cc66d6/68747470733a2f2f706f7365722e707567782e6f72672f696e69746f726d2f6462616c2f726571756972652f706870)](https://packagist.org/packages/initorm/dbal)

A small, dependency-free database abstraction layer for PHP. `initorm/dbal`gives you a thin, lazily-connecting PDO wrapper and a fluent result mapper — nothing more.

It is part of the [InitORM](https://github.com/InitORM) stack, but it has no runtime dependencies and can be used on its own anywhere PDO can.

Highlights
----------

[](#highlights)

- **Lazy connections.** No socket is opened until the first query.
- **Driver-aware DSN building.** MySQL/MariaDB, PostgreSQL, SQLite.
- **Fluent result mapper.** `asAssoc()`, `asObject()`, `asClass()`, `asLazy()`, `asArray()` / `asBoth()`.
- **Type-aware binding.** `bool` → `PARAM_BOOL`, `int` → `PARAM_INT`, `null` → `PARAM_NULL`, everything else → `PARAM_STR`.
- **In-memory query log** for debugging hotspots.
- **PSR-3 friendly logging.** Pass any `LoggerInterface`, a callable, a file path, or anything with a `critical()` method.
- **Transparent PDO forwarding.** Unknown method calls are forwarded to the underlying `PDO` / `PDOStatement`, so `lastInsertId()`, `beginTransaction()`, `closeCursor()`, etc. all work directly on the wrapper.

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

[](#installation)

```
composer require initorm/dbal
```

Requirements: **PHP 8.0+** and the `pdo` extension, plus the driver extension for the database you target (`pdo_mysql`, `pdo_pgsql`, `pdo_sqlite`).

60-second quick start
---------------------

[](#60-second-quick-start)

```
use InitORM\DBAL\Connection\Connection;

$db = new Connection([
    'driver'   => 'mysql',
    'host'     => '127.0.0.1',
    'port'     => 3306,
    'database' => 'shop',
    'username' => 'app',
    'password' => 'secret',
    'charset'  => 'utf8mb4',
]);

// Read
$user = $db->query('SELECT id, name FROM users WHERE id = :id', ['id' => 42])
           ->asAssoc()
           ->row();

// Write
$db->query(
    'INSERT INTO users (name, email) VALUES (:name, :email)',
    ['name' => 'Alice', 'email' => 'alice@example.com']
);
$newId = (int) $db->lastInsertId();      // forwarded to PDO
```

Documentation
-------------

[](#documentation)

Full docs live in [`docs/`](docs/):

- [01 · Getting Started](docs/01-getting-started.md)
- [02 · Connection](docs/02-connection.md)
- [03 · Querying](docs/03-querying.md)
- [04 · DataMapper](docs/04-data-mapper.md)
- [05 · Transactions](docs/05-transactions.md)
- [06 · Logging](docs/06-logging.md)
- [07 · Factories &amp; DI](docs/07-factories-and-di.md)
- [08 · Exceptions](docs/08-exceptions.md)
- [09 · Recipes](docs/09-recipes.md)

Testing
-------

[](#testing)

```
composer install
composer test
```

The suite runs against SQLite in-memory and finishes in well under a second.

Upgrading from 1.x
------------------

[](#upgrading-from-1x)

See [`UPGRADE.md`](UPGRADE.md). The notable breaking changes are: PHP ≥ 8.0, `src/` layout, `PDO::ATTR_PERSISTENT` defaults to `false`, `rows()` returns `[]` instead of `null` when empty, and `bind()` returns `PARAM_BOOL` for booleans.

Contributing
------------

[](#contributing)

Issues and pull requests are welcome. Please:

1. Open an issue first if you intend to make a non-trivial change.
2. Make sure `composer test` is green.
3. Cover new behaviour with a test under `tests/`.

See the organisation-wide [contribution guide](https://github.com/InitORM/.github/blob/master/CONTRIBUTING.md)for the full process.

License
-------

[](#license)

[MIT](LICENSE) © Muhammet ŞAFAK

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance94

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 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 ~224 days

Total

5

Last Release

40d ago

Major Versions

1.x-dev → 2.x-dev2026-05-24

PHP version history (2 changes)1.0PHP &gt;=7.4

2.x-devPHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b6b34f3ac8938d8ee52ba3bd260680855dc5715c7b2929d9380de30d15a67dd?d=identicon)[muhammetsafak](/maintainers/muhammetsafak)

---

Top Contributors

[![muhammetsafak](https://avatars.githubusercontent.com/u/104234499?v=4)](https://github.com/muhammetsafak "muhammetsafak (7 commits)")

---

Tags

composer-packagedata-mapperdatabasedatabase-abstraction-layerdbalinitormmariadbmysqlpdophpphp8postgresqlpsr-3sqlitedatabasemysqlsqlitedbalpdopgsqldata mapperAbstraction Layerinitorm

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/initorm-dbal/health.svg)

```
[![Health](https://phpackages.com/badges/initorm-dbal/health.svg)](https://phpackages.com/packages/initorm-dbal)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k605.0M6.8k](/packages/doctrine-dbal)[dibi/dibi

Dibi is Database Abstraction Library for PHP

5014.0M134](/packages/dibi-dibi)[aura/sqlschema

Provides facilities to read table names and table columns from a database using PDO.

44243.2k4](/packages/aura-sqlschema)[delight-im/db

Safe and convenient SQL database access in a driver-agnostic way

50174.0k7](/packages/delight-im-db)

PHPackages © 2026

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