PHPackages                             openclerk/db - 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. openclerk/db

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

openclerk/db
============

Simple PHP database management

0.1.0(11y ago)128035PHP

Since Jan 14Pushed 9y ago1 watchersCompare

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

READMEChangelogDependencies (4)Versions (2)Used By (5)

openclerk/db [![Build Status](https://camo.githubusercontent.com/8196eddece1c5852bf08168219a9b9199b3cb3ef00a0353362530a856b097619/68747470733a2f2f7472617669732d63692e6f72672f6f70656e636c65726b2f64622e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/openclerk/db)
================================================================================================================================================================================================================================================================================

[](#openclerkdb-)

A library for MySQL database management in Openclerk, supporting migrations, connection abstraction and automated replication switching.

Installing
----------

[](#installing)

Include `openclerk/db` as a requirement in your project `composer.json`, and run `composer update` to install it into your project:

```
{
  "require": {
    "openclerk/db": "^0.1"
  }
}
```

Using
-----

[](#using)

Use [component-discovery](https://github.com/soundasleep/component-discovery) to enable discovery of migrations across all of your dependencies. Update your `discovery.json`:

```
{
  "components": {
    "migrations": "migrations.json"
  }
}
```

You can then define your own migrations using `migrations.json` in each component:

```
{
  "my_migration_1": "\\My\\Migration"
}
```

Configure your database connection, optionally through a helper function `db()`(see also [openclerk/config](https://github.com/openclerk/config) project):

```
use \Openclerk\Config;

function db() {
  return new \Db\SoloConnection(
    Config::get("database_name"),
    Config::get("database_username"),
    Config::get("database_password")
  );
}
```

Load them up and optionally install them at runtime:

```
$logger = new \Monolog\Logger('name');

class AllMigrations extends \Db\Migration {
  function getParents() {
    return array(new Db\BaseMigration()) + DiscoveredComponents\Migrations::getAllInstances();
  }
}

$migrations = new AllMigrations(db());
if ($migrations->hasPending(db())) {
  $migrations->install(db(), $logger);
}
```

Migrations can be [discovered and loaded at runtime](https://github.com/soundasleep/component-discovery) with a `migrations.json`.

You can also generate migrations at runtime, for example [generating a table for each Currency discovered at runtime](https://github.com/soundasleep/openclerk/blob/master/core/Migrations/BlockCountMigrationGenerator.php).

Replication
-----------

[](#replication)

You can also define replication connections which are selected based on the type of query, and whether that table has recently been updated in the current $\_SESSION:

```
function db() {
  return new \Db\ReplicatedConnection(
    Config::get("database_host_master"),
    Config::get("database_host_slave"),
    Config::get("database_name"),
    Config::get("database_username"),
    Config::get("database_password")
  );
}
```

Events
------

[](#events)

A number of [events](https://github.com/openclerk/events) are triggered by the library, and can be captured for [metrics](https://github.com/openclerk/metrics):

- `db_prepare_start`, `db_prepare_end`, `db_prepare_master`, `db_prepare_slave`
- `db_execute_start`, `db_execute_end`
- `db_fetch_start`, `db_fetch_end`
- `db_fetch_all_start`, `db_fetch_all_end`

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity53

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

Unknown

Total

1

Last Release

4142d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1ebbec5ccc867054461adebb7c5b6312f8256f989ef96b124892e6e89724afdb?d=identicon)[soundasleep](/maintainers/soundasleep)

---

Top Contributors

[![soundasleep](https://avatars.githubusercontent.com/u/3889656?v=4)](https://github.com/soundasleep "soundasleep (49 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/openclerk-db/health.svg)

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

###  Alternatives

[wazaari/monolog-mysql

A handler for Monolog that sends messages to MySQL

140884.1k6](/packages/wazaari-monolog-mysql)[nkiraly/dbsteward

SQL database definition differencing tool. Structure and data is defined in a DTD-enforced, human-readable XML format. Outputs transactional SQL statement files to apply your changes.

504.2k](/packages/nkiraly-dbsteward)

PHPackages © 2026

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