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(2y ago)0401BSD-3-ClausePHPPHP &gt;=5.3.3

Since Jun 8Pushed 7mo ago1 watchersCompare

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

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

24

—

LowBetter than 31% of packages

Maintenance43

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity32

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

752d 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

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M117](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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