PHPackages                             ezweb/dblinker - 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. ezweb/dblinker

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

ezweb/dblinker
==============

3.2.1(3y ago)119.4k9[2 PRs](https://github.com/ezweb/dblinker/pulls)MITPHPPHP ^7.4 || ^8.1

Since May 28Pushed 3y ago11 watchersCompare

[ Source](https://github.com/ezweb/dblinker)[ Packagist](https://packagist.org/packages/ezweb/dblinker)[ RSS](/packages/ezweb-dblinker/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (37)Used By (0)

DB Linker
=========

[](#db-linker)

Database connection for master/slaves setup. This package provides drivers for [DBAL](https://github.com/doctrine/dbal). `MasterSlavesDriver` for auto switching between a master and slaves servers &amp; `RetryDriver` for retrying query when some errors occurs.

[![Build Status](https://camo.githubusercontent.com/13f01dad9f35829c380a699552a74f4b5fa5806333064d512a3d14d0965931ff/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f657a7765622f64626c696e6b65722e737667)](https://travis-ci.org/ezweb/dblinker)[![Code Status](https://camo.githubusercontent.com/0986c0499fe4ddc544211edbb1d0e7834c704e4c7dc1038f7dd1a9b14768ade9/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f657a7765622f64626c696e6b65722e737667)](https://scrutinizer-ci.com/g/ezweb/dblinker/build-status/master)[![Latest Version](https://camo.githubusercontent.com/45c116da65af6daf410d6b3964a48e2172d3ad0f88c5af15c7f9e8a481ff5d3d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f657a7765622f64626c696e6b65722e737667)](https://packagist.org/packages/ezweb/dblinker)[![License](https://camo.githubusercontent.com/dd3d150c278ec6d1dc65f49fef199894d94e82176dca3a2b815fa1803faf48a5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f657a7765622f64626c696e6b65722e737667)](https://packagist.org/packages/ezweb/dblinker)

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

[](#installation)

run `composer require ezweb/dblinker`

Configuration
-------------

[](#configuration)

### Master/Slaves connection

[](#masterslaves-connection)

A `MysqlMasterSlavesConnection` wraps a mysql master connection &amp; one or more mysql slaves connection. It execute "READ" queries on one of the slaves connections and "WRITE" queries on the master connection.

```
// master and slaves configuration
$master = [
    'driver' => 'mysqli',
    'host' => $masterHostname,
    'user' => $masterUsername,
    'password' => $masterPassword,
    'dbname' => $masterDb,
];

$slaves = [
    [
        'driver' => 'mysqli',
        'host' => $slave1Hostname,
        'user' => $slave1Username,
        'password' => $slave1Password,
        'dbname' => $slave1Db,
        'weight' => $slave1Weight,
    ],
    /** other slaves params **/
];

// connection configuration
$params = [
    'master' => $master,
    'slaves' => $slaves,
    'driverClass' => 'Ez\DbLinker\Driver\MysqlMasterSlavesDriver',
];

// Doctrine\DBAL\Configuration
$connection = Doctrine\DBAL\DriverManager::getConnection($params);

var_dump($connection->fetchColumn('SELECT 1')); // slave
var_dump($connection->exec('INSERT INTO…')); // master
```

### Retry connection

[](#retry-connection)

A `MysqlRetryConnection` wraps another mysql connection. Its goal is to transparently re-execute queries that provokes erros when it's possible to recover automatically.

```
// master and slaves configuration
$params = [
    'connectionParams' => [
        /** mysql master/slaves, mysqli or pdo_mysql parameters **/
    ],
    'driverClass' => 'Ez\DbLinker\Driver\MysqlRetryDriver',
    'retryStrategy' => new Ez\DbLinker\RetryStrategy\MysqlRetryStrategy,
]

// Doctrine\DBAL\Configuration
$connection = Doctrine\DBAL\DriverManager::getConnection($params);

var_dump($connection->fetchColumn('SELECT 1')); // nothing special
var_dump($connection->exec('SET SESSION WAIT_TIMEOUT = 1'));
sleep(2);
var_dump($connection->fetchColumn('SELECT 1')); // Connection will catch "MySQL has gone away", re-execute the query and return the results as if nothing happened
```

Usage
-----

[](#usage)

When using `Doctrine\DBAL\DriverManager`, the `$connection` it returns is an instance of `Doctrine\DBAL\Connection`, that wraps one or more `*Connection`. Take a look at [its documentation](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/data-retrieval-and-manipulation.html) for more information.

Note: You can nest a `MysqlMasterSlavesConnection` in a `MysqlRetryConnection`.

Tests
-----

[](#tests)

To run the test suite, you need Docker &amp; Docker-Compose:

```
docker-compose run composer install
docker-compose run behat

```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~231 days

Total

30

Last Release

1314d ago

Major Versions

v1.5.0 → 2.0.02017-09-05

2.0.0 → 3.0.02017-12-14

v1.6.0 → 3.2.02022-04-13

2.1.0-beta → 3.2.12022-10-12

PHP version history (4 changes)2.0.0PHP ^7.1

3.0.0PHP ^7

3.1.5PHP ^7.4

v1.6.0PHP ^7.4 || ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/0ae72ae4e4833104579245d00170472c0aab7363f19a0df1d3a6022afd461591?d=identicon)[arsonik](/maintainers/arsonik)

![](https://www.gravatar.com/avatar/6e75b21a7f4497127b701821bb4a3e973ce1b0c5a03832c20edb89b2ebda82db?d=identicon)[gregorg](/maintainers/gregorg)

---

Top Contributors

[![arsonik](https://avatars.githubusercontent.com/u/1333734?v=4)](https://github.com/arsonik "arsonik (35 commits)")[![mathroc](https://avatars.githubusercontent.com/u/291531?v=4)](https://github.com/mathroc "mathroc (30 commits)")[![gregorg](https://avatars.githubusercontent.com/u/541602?v=4)](https://github.com/gregorg "gregorg (13 commits)")[![duvall](https://avatars.githubusercontent.com/u/2330728?v=4)](https://github.com/duvall "duvall (2 commits)")[![fletanoux](https://avatars.githubusercontent.com/u/20419439?v=4)](https://github.com/fletanoux "fletanoux (1 commits)")

###  Code Quality

TestsBehat

### Embed Badge

![Health badge](/badges/ezweb-dblinker/health.svg)

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

###  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)[martin-georgiev/postgresql-for-doctrine

Extends Doctrine with native PostgreSQL support for arrays, JSONB, ranges, PostGIS geometries, text search, ltree, uuid, and 100+ PostgreSQL-specific functions.

4485.3M4](/packages/martin-georgiev-postgresql-for-doctrine)[damienharper/auditor-bundle

Integrate auditor library in your Symfony projects.

4542.8M](/packages/damienharper-auditor-bundle)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[overtrue/laravel-versionable

Make Laravel model versionable.

585308.0k5](/packages/overtrue-laravel-versionable)[worksome/foggy

Foggy is a tool for making database dumps with some data removed/changed.

26571.7k1](/packages/worksome-foggy)

PHPackages © 2026

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