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

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

eufony/dbal
===========

Zero-configuration extensible PHP database abstraction layer library.

v1.x-dev(3y ago)0191LGPL-3.0-or-laterPHPPHP ^8.2

Since Feb 7Pushed 3y ago1 watchersCompare

[ Source](https://github.com/eufony/dbal)[ Packagist](https://packagist.org/packages/eufony/dbal)[ RSS](/packages/eufony-dbal/feed)WikiDiscussions v1.x Synced 1mo ago

READMEChangelogDependencies (7)Versions (3)Used By (1)

The Eufony DBAL Package
=======================

[](#the-eufony-dbal-package)

 [ ![Packagist Downloads](https://camo.githubusercontent.com/cb2d1dd4be1de80656bccc98a282b29eed679c61da5633472c7cac1750ac8c5c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6575666f6e792f6462616c3f6c6162656c3d5061636b6167697374253230446f776e6c6f616473) ](https://packagist.org/packages/eufony/dbal) [ ![GitHub Stars](https://camo.githubusercontent.com/cea0c47c67b9b10d702c277bcee10466fc7866dc3de72bf07600de345fa74c07/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6575666f6e792f6462616c3f6c6162656c3d4769744875622532305374617273) ](https://github.com/eufony/dbal) [ ![Issues](https://camo.githubusercontent.com/3593de57f2b629cffdb5b45d5d726644c58e97c54120d070c095929d57383f48/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6575666f6e792f6462616c2f6f70656e3f6c6162656c3d497373756573) ](https://github.com/eufony/dbal/issues)
 [ ![License](https://camo.githubusercontent.com/473bb9403cc2e59432a97da35933071e8c0883046a8a41603982af388f86f866/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6575666f6e792f6462616c3f6c6162656c3d4c6963656e7365) ](https://github.com/eufony/dbal#license) [ ![Community Built](https://camo.githubusercontent.com/db7f0b0f807877959a4badf1f8b12ae274bdf86899e95fc41e39aefb6ba5cc1c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d616465253230776974682d2545322539442541342d726564) ](https://github.com/eufony/dbal#contributing)

*eufony/dbal provides an abstraction layer over SQL to ease development using relational database management systems and to prevent lock-in to a specific SQL flavor.*

*eufony/dbal* is a PHP library that handles interfacing with the relational database of your choice. It uses an expressive syntax that is then translated on-the-fly to the appropriate syntax for your SQL flavor. Using it, you'll enjoy all the benefits of plain SQL, plus:

- [PSR-3](https://www.php-fig.org/psr/psr-3/) compatible logging of database events.
- Transparent caching of query results using any [PSR-6](https://www.php-fig.org/psr/psr-6/)or [PSR-16](https://www.php-fig.org/psr/psr-16/) compliant caching implementation.
- Easy protection against SQL injection attacks using prepared statements.
- No-fuss serialization / unserialization of any valid PHP type.

Interested? [Here's how to get started.](#getting-started)

FAQ
---

[](#faq)

### Why not write my own SQL queries directly?

[](#why-not-write-my-own-sql-queries-directly)

The problem with plain old SQL is that "SQL" unfortunately does not refer to a single thing. Instead, it comes in different "flavors", each of which have slight variations on their syntax and supported features. Nobody writes "SQL" queries. You always have to target a specific flavor.

*"Okay, what if I only use SQL functions and syntax that are part of a universal SQL standard?"*

While there is such a thing as an SQL "standard" adopted by both [ANSI](https://ansi.org/) and [ISO](https://iso.org/), you'll quickly face two problems when trying to write queries that comply with it:

1. Some very basic functionality, such as that of the [MySQL](https://mysql.com/) `LIMIT` and `OFFSET` keywords, are inexplicably missing from the standard instruction set. In such situations, you're forced to either rewrite your query in hacky ways that try to accomplish the same result, or give up and only target a specific flavor, which might (will) cause portability problems later on.
2. Different SQL flavors comply with the standard to a wildly varying degree. While [PostgreSQL](https://postgresql.org/) and [SQLite](https://sqlite.org/) are *mostly* compliant (at least, with the core standard, disregarding the various extensions), you'll still come across small differences that break things in very subtle ways that might otherwise go unnoticed. Trying to take these into account will add significant overhead to development and will generally make it unmotivating to work on the backend infrastructure.

*eufony/dbal* takes care of these problem for you. As an abstraction layer, you, as a developer, don't have to worry at all about the syntax that comes out the other end. If you want to migrate flavors, you only need to switch to any of the ready-made [driver implementations](https://packagist.org/providers/eufony/dbal-driver-implemtation); or, if one doesn't exist, [contribute](#contributing) and [make your own](docs/Supporting_other_Databases.md). Additionally, you'll get to enjoy some creature comforts when interacting with your database from PHP; such as transparent logging, caching, and conversion between PHP and SQL data types.

### Why not use a more well-established, mature project?

[](#why-not-use-a-more-well-established-mature-project)

*Because trusting your critical infrastructure to untested, unfunded, emerging projects is fun and exciting!*

On a more serious note, *eufony/dbal* was started as a sister project to [*eufony/orm*](https://github.com/eufony/orm), an [Object Relational Mapping](https://en.wikipedia.org/wiki/Object-relational_mapping) library that aims to rethink the disadvantages of relational database models with an inventive pragmatic approach. It was concluded during early development that supporting multiple SQL flavors [was impractical](#why-not-write-my-own-sql-queries-directly) without an abstraction layer on top of SQL.

As such, the project was split into two, with *eufony/orm* providing the "top" and *eufony/dbal* providing the "bottom" halves, in much the same way as other popular projects such as the [Doctrine ORM](https://github.com/doctrine/orm). Unlike the Doctrine project, however, *eufony/dbal* also tries to create an expressive syntax for using its query builders, as they are something that the end-user (you) can reasonably be expected to interact with.

Getting started
---------------

[](#getting-started)

### Installation

[](#installation)

*eufony/dbal* is released as a [Packagist](https://packagist.org/) package and can be easily installed via [Composer](https://getcomposer.org/) with:

```
composer require "eufony/dbal:v1.x-dev"

```

> **Warning**: This package ***does not have any stable releases*** yet (not even a v0.x pre-release) and is currently ***unstable***. Expect frequent breaking changes and instability!

### Basic Usage

[](#basic-usage)

*For a more detailed documentation, see [here](docs).*

*eufony/dbal* is a "zero-configuration" library, making it blazingly fast to get started. Just define a new database connection and (optionally) give it a name, like so:

```
$driver = /* ... */;
$database = new Connection($driver, key: "default");
```

The driver can be any implementation of the driver interface. Out of the box, *eufony/dbal* supports PostgreSQL, MySQL, and SQLite:

```
// PostgreSQL
$postgres = new PostgreSQLDriver($dsn, $user, $password);

// MySQL
$mysql = new MySQLDriver($dsn, $user, $password);

// SQLite
$sqlite = new SQLiteDriver($path); // $path can also be `:memory:` for an ephemeral database
```

All three drivers use the PHP PDO extension under the hood.

Once your connection is activated, you can immediately start building and sending queries to the database:

```
// Define the query
$query = Select::from("users");

// You can also extend the query using loops, conditional logic, etc.
if ($fetch_ids_only) {
    $query = $query->fields(["id"]);
}

// Generate the query string and send it to the database for execution
$users = $query->execute();
```

You can find a list of example queries [here](docs/Queries.md).

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

[](#contributing)

Found a bug or a missing feature? Report it over at the [issue tracker](https://github.com/eufony/dbal/issues).

License
-------

[](#license)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see .

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

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

Total

3

Last Release

1190d ago

Major Versions

v0.1.0-beta1 → v1.x-dev2023-02-12

PHP version history (2 changes)v0.1.0-alpha1PHP ^8.1

v1.x-devPHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/7b73d2ffc86da306523c3c4fb19e002ba203ed2819b14db27d7b510bb58b2c3d?d=identicon)[ahgencer](/maintainers/ahgencer)

---

Top Contributors

[![ahgencer](https://avatars.githubusercontent.com/u/33004442?v=4)](https://github.com/ahgencer "ahgencer (153 commits)")

---

Tags

dbaleufonyphpsqldbalsqleufony

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[doctrine/dbal

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

9.7k578.4M5.6k](/packages/doctrine-dbal)[cycle/database

DBAL, schema introspection, migration and pagination

64690.9k31](/packages/cycle-database)[tommyknocker/pdo-database-class

Framework-agnostic PHP database library with unified API for MySQL, MariaDB, PostgreSQL, SQLite, MSSQL, and Oracle. Query Builder, caching, sharding, window functions, CTEs, JSON, migrations, ActiveRecord, CLI tools, AI-powered analysis. Zero external dependencies.

845.7k](/packages/tommyknocker-pdo-database-class)[mrjgreen/database

Expressive Database Layer for PHP - Based on Illuminate/Database

5347.8k10](/packages/mrjgreen-database)

PHPackages © 2026

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