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

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

tjm/db
======

Simple PDO abstraction for querying and other database utilities

v0.2.0(1y ago)0391BSD-3-ClausePHPPHP &gt;=5.3.3

Since Jun 8Pushed 6mo ago1 watchersCompare

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

READMEChangelogDependenciesVersions (11)Used By (1)

DB
==

[](#db)

This project is a simple PDO abstraction for database querying and other utilities. It is still early stage and the interface is still being decided, with a good chance of breaking changes.

The two important classes that are likely to stay and remain similar to their description here are `TJM\DB`, which represents a PDO connection, and `TJM\DB\Statement`, which is a wrapper around a `PDOStatement`. `DB` has a `query()` method that can be passed a query and parameters. It will execute it and return a `Statement` from which we can `fetch()` our results. Example usage taking advantage of reuse of the statement:

```
$db = new TJM\DB('mysql:dbname=thedb;host=localhost', 'me', '12345');
$query = "SELECT id, name FROM posts WHERE id = :id";
foreach([5, 6] as $id){
	$query = $db->query($query, ['id'=> $id]);
	while($item = $query->fetch()){
		var_dump($item);
	}
}
```

Can optionally connect through SSH tunnel to remote server if `sshID` is set, optionally with `sshDBConnection`.

`DB` will automatically attempt to reconnect to the database if the connection is broken, which can happen in long running scripts, for example.

The query can be an array or object with a special format meant to make progressively building a query easier, but that interface is still being worked out. Examples of some of these formats that are currently supported can be seen in the unit tests, but there's a chance some of those won't be supported in the future.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance51

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

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

Total

10

Last Release

707d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/731711?v=4)[Toby Mackenzie](/maintainers/tobymackenzie)[@tobymackenzie](https://github.com/tobymackenzie)

---

Top Contributors

[![tobymackenzie](https://avatars.githubusercontent.com/u/731711?v=4)](https://github.com/tobymackenzie "tobymackenzie (32 commits)")

### Embed Badge

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

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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