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 Jun 26Pushed 1w ago1 watchersCompare

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

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

22

—

LowBetter than 21% of packages

Maintenance64

Regular maintenance activity

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity11

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://avatars.githubusercontent.com/u/49325097?v=4)[michaelrushton](/maintainers/michaelrushton)[@MichaelRushton](https://github.com/MichaelRushton)

---

Top Contributors

[![MichaelRushton](https://avatars.githubusercontent.com/u/49325097?v=4)](https://github.com/MichaelRushton "MichaelRushton (15 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

[jdorn/sql-formatter

a PHP SQL highlighting library

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

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

8351.6M87](/packages/propel-propel1)[pgvector/pgvector

pgvector support for PHP

198741.5k12](/packages/pgvector-pgvector)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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