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

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

bentools/simple-dbal
====================

v0.6(7y ago)31.7k[1 PRs](https://github.com/bpolaszek/simple-dbal/pulls)2MITPHPPHP &gt;=7.1

Since May 18Pushed 5y ago2 watchersCompare

[ Source](https://github.com/bpolaszek/simple-dbal)[ Packagist](https://packagist.org/packages/bentools/simple-dbal)[ RSS](/packages/bentools-simple-dbal/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (1)Dependencies (8)Versions (8)Used By (2)

[![Latest Stable Version](https://camo.githubusercontent.com/4af52a9f51d33519a7a528c5a2dc006fb7cbb9af69a06a837005e41e7ea0ee19/68747470733a2f2f706f7365722e707567782e6f72672f62656e746f6f6c732f73696d706c652d6462616c2f762f737461626c65)](https://packagist.org/packages/bentools/simple-dbal)[![License](https://camo.githubusercontent.com/06a4aa44457bde2ff9933edd8659a065fe71d9c7249c83b550afdc036590a2c8/68747470733a2f2f706f7365722e707567782e6f72672f62656e746f6f6c732f73696d706c652d6462616c2f6c6963656e7365)](https://packagist.org/packages/bentools/simple-dbal)[![Quality Score](https://camo.githubusercontent.com/611459229c681c67197850f360b17919bd003e41912f7cf4a384cf38d19aa25d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f62706f6c61737a656b2f73696d706c652d6462616c2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bpolaszek/simple-dbal)[![Total Downloads](https://camo.githubusercontent.com/91a3efa2492ae9aba796a37e97cc925126bdfe21671f72758bdc05d37e96abc0/68747470733a2f2f706f7365722e707567782e6f72672f62656e746f6f6c732f73696d706c652d6462616c2f646f776e6c6f616473)](https://packagist.org/packages/bentools/simple-dbal)

SimpleDBAL
==========

[](#simpledbal)

A modern wrapper on top of PDO and Mysqli, written in PHP7.1. It aims at exposing the same API regardless of the one your project uses.

Introduction
------------

[](#introduction)

PHP offers 2 different APIs to connect to a SQL database: `PDO` and `mysqli` (we won't talk about `mysql_*` functions since they're deprecated). Both do more or less the same thing, but:

- Their API are completely different (different method names and signatures)
- They both have their own pros and cons.
- Some features of one are missing in the other.

This library exposes an API that can be used by any of them, transparently, in a more modern approach (OOP, iterators, return types, etc).

This also means you can switch from `PDO` to `mysqli` and vice-versa without having to rewrite your whole code.

From my personnal experience, I was used to `PDO` and was forced to deal with `mysqli` in another project and it was really messy.

Overview
--------

[](#overview)

```
use BenTools\SimpleDBAL\Model\Credentials;
use BenTools\SimpleDBAL\Model\SimpleDBAL;

$credentials = new Credentials('localhost', 'user', 'password', 'database');
$cnx         = SimpleDBAL::factory($credentials, SimpleDBAL::PDO);
$query       = "SELECT `id`, `name` FROM guys WHERE created_at > ?";
foreach ($cnx->execute($query, [new DateTime('-1 month')]) as $item) {
    var_dump($item['name']);
}
```

Additionnal features
--------------------

[](#additionnal-features)

- On-the-fly parameter binding for prepared statements (simply pass an array of arguments after the query)
- `DateTimeInterface` objects automatic binding (formats to YYYY-MM-DD HH:ii:ss)
- [Asynchronous queries](doc/03-AsynchronousQueries.md) (Promises)
- [Parallel queries](doc/03-AsynchronousQueries.md#parallel-queries)
- Support for named parameters in prepared statements for `mysqli` (polyfill with regexps - experimental feature)
- Can [silently reconnect](doc/02-Configuration.md) after a lost connection

The `Result` object
-------------------

[](#the-result-object)

Every query sent to the adapter will return a `BenTools\SimpleDBAL\Contract\ResultInterface` object.

For *SELECT* queries, use the following methods:

- `$result->asArray()` to fetch an array containing the whole resultset
- `$result->asRow()` to fetch the 1st row of the resultset, as an associative array
- `$result->asList()` to fetch the 1st column of the resultset, as a sequential array
- `$result->asValue()` to fetch a single value (i.e the 1st column of the 1st row)
- `foreach ($result as $row)` to iterate over the resultset (uses lazy-loading)
- `count($result)` to return the number of rows of the resultset.

For *INSERT* / *UPDATE* / *DELETE* queries, use the following methods:

- `count($result)` to return the number of affected rows
- `$result->getLastInsertId()` to get the id of the last inserted row or sequence value.

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

[](#installation)

```
composer require bentools/simple-dbal

```

Tests
-----

[](#tests)

```
./vendor/bin/phpunit

```

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

[](#documentation)

[Getting started](doc/01-GettingStarted.md)

[Configuring auto-reconnect](doc/02-Configuration.md)

[Asynchronous and parallel queries](doc/03-AsynchronousQueries.md)

[Connection pools](doc/04-ConnectionPools.md)

[Known Issues](doc/05-KnownIssues.md)

###  Health Score

28

—

LowBetter than 51% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 59.1% 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 ~208 days

Recently: every ~313 days

Total

7

Last Release

2121d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/acdd1a8ee0e657ddd06cf11f98a32100ef7121afb8aa270a5b295f5c29c038b3?d=identicon)[bpolaszek](/maintainers/bpolaszek)

---

Top Contributors

[![bpolaszek](https://avatars.githubusercontent.com/u/5569077?v=4)](https://github.com/bpolaszek "bpolaszek (13 commits)")[![ben-synapse](https://avatars.githubusercontent.com/u/36077477?v=4)](https://github.com/ben-synapse "ben-synapse (9 commits)")

---

Tags

databasemysqlmysqlipdophp

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k555.0M2.8k](/packages/aws-aws-sdk-php)[guzzlehttp/guzzle

Guzzle is a PHP HTTP client library

23.5k1.1B37.5k](/packages/guzzlehttp-guzzle)[laravel/framework

The Laravel Framework.

34.9k556.2M21.3k](/packages/laravel-framework)[kreait/firebase-php

Firebase Admin SDK

2.4k46.0M90](/packages/kreait-firebase-php)[google/cloud-core

Google Cloud PHP shared dependency, providing functionality useful to all components.

346137.0M126](/packages/google-cloud-core)[google/gax

Google API Core for PHP

268121.1M619](/packages/google-gax)

PHPackages © 2026

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