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

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

michaelrushton/db
=================

A PHP library to query a database.

018PHP

Since Mar 5Pushed 2mo ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

PHP DB
======

[](#php-db)

A PHP library to query a database.

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

[](#installation)

```
composer require michaelrushton/php-db
```

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

[](#documentation)

### Drivers

[](#drivers)

- [MariaDB](docs/drivers/mariadb.md)
- [MySQL](docs/drivers/mysql.md)
- [PostgreSQL](docs/drivers/postgresql.md)
- [SQLite](docs/drivers/sqlite.md)
- [SQL Server](docs/drivers/sqlserver.md)

### Connection

[](#connection)

#### exec

[](#exec)

See .

```
$count = $connection->exec("DELETE FROM users");
```

#### query

[](#query)

See .

```
$pdo_stmt = $connection->query("SELECT * FROM users");
$pdo_stmt = $connection->query("SELECT * FROM users", $fetchMode, ...$fetchModeArgs);
```

#### prepare

[](#prepare)

See .

```
$pdo_stmt = $connection->prepare("SELECT * FROM users WHERE id = ?");
$pdo_stmt = $connection->prepare("SELECT * FROM users WHERE id = ?", $options);
```

#### execute

[](#execute)

See .

```
$pdo_stmt = $connection->execute("SELECT * FROM users WHERE id = ?", [1]);
```

#### fetch

[](#fetch)

See .

```
$user = $connection->fetch("SELECT * FROM users WHERE id = ?", [1]);
$user = $connection->fetch("SELECT * FROM users WHERE id = ?", [1], $mode, $cursorOrientation, $cursorOffset);
```

#### fetchAll

[](#fetchall)

See .

```
$users = $connection->fetchAll("SELECT * FROM users WHERE status = ?", [1]);
$users = $connection->fetchAll("SELECT * FROM users WHERE status = ?", [1], $mode, ...$args);
```

#### fetchColumn

[](#fetchcolumn)

See

```
$id = $connection->fetchColumn("SELECT * FROM users WHERE id = ?", [1]);
$id = $connection->fetchColumn("SELECT * FROM users WHERE id = ?", [1], $column);
```

#### fetchObject

[](#fetchobject)

See

```
$user = $connection->fetchObject("SELECT * FROM users WHERE id = ?", [1]);
$user = $connection->fetchObject("SELECT * FROM users WHERE id = ?", [1], $class, $constructorArgs);
```

#### yield

[](#yield)

See .

```
$generator = $connection->yield("SELECT * FROM users WHERE status = ?", [1]);
$generator = $connection->yield("SELECT * FROM users WHERE status = ?", [1], $mode, $cursorOrientation, $cursorOffset);
```

#### transaction

[](#transaction)

Begins a transaction, rolls back if an exception is thrown (rethrowing the exception), else commits.

```
use MichaelRushton\DB\Connection;

$connection->transaction(function (Connection $connection)
{
    $connection->query("INSERT INTO users (id) VALUES (1)");
    $connection->query("INSERT INTO users (id) VALUES (2)");
});
```

### Query builders

[](#query-builders)

- [INSERT](docs/statements/insert.md)
- [SELECT](docs/statements/select.md)
- [UPDATE](docs/statements/update.md)
- [DELETE](docs/statements/delete.md)
- [REPLACE](docs/statements/replace.md)

#### exec

[](#exec-1)

```
$count = $connection->delete()->from('users')->exec();
```

#### query

[](#query-1)

```
$pdo_stmt = $connection->select()->from('users')->query();
$pdo_stmt = $connection->select()->from('users')->query($fetchMode, ...$fetchModeArgs);
```

#### prepare

[](#prepare-1)

```
$pdo_stmt = $connection->select()->from('users')->where('id = ?')->prepare();
$pdo_stmt = $connection->select()->from('users')->where('id = ?')->prepare($options);
```

#### execute

[](#execute-1)

```
$pdo_stmt = $connection->select()->from('users')->where('id', 1)->execute();
```

#### fetch

[](#fetch-1)

```
$user = $connection->select()->from('users')->where('id', 1)->fetch();
$user = $connection->select()->from('users')->where('id', 1)->fetch($mode, $cursorOrientation, $cursorOffset);
```

#### fetchAll

[](#fetchall-1)

```
$users = $connection->select()->from('users')->where('status', 1)->fetchAll();
$users = $connection->select()->from('users')->where('status', 1)->fetchAll($mode, ...$args);
```

#### fetchColumn

[](#fetchcolumn-1)

```
$id = $connection->select()->from('users')->where('id', 1)->fetchColumn();
$id = $connection->select()->from('users')->where('id', 1)->fetchColumn($column);
```

#### fetchObject

[](#fetchobject-1)

```
$user = $connection->select()->from('users')->where('id', 1)->fetchObject();
$user = $connection->select()->from('users')->where('id', 1)->fetchObject($class, $constructorArgs);
```

#### yield

[](#yield-1)

```
$generator = $connection->select()->from('users')->where('status', 1)->yield();
$generator = $connection->select()->from('users')->where('status', 1)->yield($mode, $cursorOrientation, $cursorOffset);
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance57

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity12

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2ddefabb272f816931643e2fe5540917d89b0b65529276ffe3195c2e6ec39d62?d=identicon)[michaelrushton](/maintainers/michaelrushton)

---

Top Contributors

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

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/michaelrushton-db/health.svg)](https://phpackages.com/packages/michaelrushton-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.

90440.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)
