PHPackages                             alexccavaco/database - 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. alexccavaco/database

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

alexccavaco/database
====================

MySQL Database Query Builder for PHP

0.1.7(5y ago)135MITPHPPHP &gt;=5.3.0

Since May 27Pushed 5y agoCompare

[ Source](https://github.com/AlexCCavaco/Database)[ Packagist](https://packagist.org/packages/alexccavaco/database)[ RSS](/packages/alexccavaco-database/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (10)Dependencies (1)Versions (15)Used By (0)

Database
========

[](#database)

A Database Query Builder for PHP

There are four classes from where to start building: **DBDelete**, **DBInsert**, **DBSelect** and **DBUpdate**

These are assigned to equivalent MySQL queries.

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

[](#installation)

```
  composer require alexccavaco/database

```

Examples
--------

[](#examples)

Select Query:

```
  $r=DBSelect::from('table')
    ->select('*')
    ->where('column1 = ?', $data1)
    ->where('column2 = ?', $data2)
    ->orderBy('name')
    ->run($db);

  $r->fetch(\PDO::FETCH_ASSOC);

```

Delete Query:

```
  $r=DBUpdate::table('table')
    ->set('column','?',$param)
    ->setAll(['column'=>$param,'anotherCol'=>$param2])
    ->where('column = ?','data')
    ->run($db);

  $r->fetch(\PDO::FETCH_ASSOC);

```

Insert Query:

```
  $r=DBInsert::into('table')
    ->value('column1',$param1)
    ->value('column2',$param2,true) //The third parameter if true automatically sets On Duplicate Update
    ->values(['column'=>$param])
    ->run($db);

  $r->fetch(\PDO::FETCH_ASSOC);

```

Delete Query:

```
  $r=DBDelete::from('table')
    ->where('column = ?','data')
    ->limit(2)
    ->run($db);

  $r->fetch(\PDO::FETCH_ASSOC);

```

Complex Queries can be created, using joins, having... but these are just a few examples.

Database Class
--------------

[](#database-class)

With the package comes a Database Class. This class sets some attributes by default (such as the use of exceptions for errors and emulate prepares) and its constructor eases the setting of charsets and timezones for mysql.

Two functions come with it:

- prepRun - Eases the preparation of statements, preparing and executing them before returning
- logStatement - Receives a PSR Logger and a log type to log every query and parameters (for debugging)

**This class is completely optional.**

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

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

Every ~43 days

Recently: every ~68 days

Total

14

Last Release

1989d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0fc05d913ff59b984cc9cf5c8bb02ea8674c9711715da99949ba67c6eaf6c173?d=identicon)[AlexCCavaco](/maintainers/AlexCCavaco)

---

Top Contributors

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

---

Tags

databasemysqlquery builder

### Embed Badge

![Health badge](/badges/alexccavaco-database/health.svg)

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

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[cycle/database

DBAL, schema introspection, migration and pagination

64690.9k31](/packages/cycle-database)[tommyknocker/pdo-database-class

Framework-agnostic PHP database library with unified API for MySQL, MariaDB, PostgreSQL, SQLite, MSSQL, and Oracle. Query Builder, caching, sharding, window functions, CTEs, JSON, migrations, ActiveRecord, CLI tools, AI-powered analysis. Zero external dependencies.

845.7k](/packages/tommyknocker-pdo-database-class)[opis/database

A database abstraction layer over PDO, that provides a powerful and intuitive query builder, bundled with an easy to use schema builder

10184.2k3](/packages/opis-database)

PHPackages © 2026

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