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

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

rdx/db
======

Simple MySQL/SQLite wrapper

1.28(1y ago)6285[9 issues](https://github.com/rudiedirkx/db_generic/issues)MITPHP

Since Oct 29Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/rudiedirkx/db_generic)[ Packagist](https://packagist.org/packages/rdx/db)[ RSS](/packages/rdx-db/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (30)Used By (0)

The most elegant, simple, beautiful DBAL ever.
==============================================

[](#the-most-elegant-simple-beautiful-dbal-ever)

Drivers / adapters / databases
------------------------------

[](#drivers--adapters--databases)

- SQLite 3 ([via PDO](http://nl3.php.net/manual/en/ref.pdo-sqlite.php))
- MySQLi

No SQLite 2 or procedural MySQL. What is it, 2003?

Where to start
--------------

[](#where-to-start)

Check out the `test/` folder. It contains a few **simple** tests/examples.

Check out the projects where it's used. A powerful, **very useful** feature is the schema 'sync': create tables, columns, indexes, relations and fixtures, all in 1 clean array.

Do it! You can create other drivers. Just extend `db_generic` and `db_generic_result`. You can call it `db_pgsql` =) NoSQL won't work, because there's no Query builder (and there won't be).

Show me examples!
-----------------

[](#show-me-examples)

Okay.

Simple select. Will return an Iterable.

```
$users = $db->select('users', 'lastname  ?', array("De'sander"));
print_r($users); // NOT a list of users

```

Get the first result object.

```
$user = $users->nextObject();
var_dump($user->lastname);

```

Do a GROUP BY and get a 2D array.

```
$users_by_lastname = $db->select_fields('users', 'lastname, COUNT(1)', 'active = ? GROUP BY lastname', array(1));
var_dump($users_by_lastname["De'sander"]);

```

Another one. Perfect for HTML ``s.

```
$options = $db->select_fields('countries', 'code, name', array('active' => 1));

```

Return objects in a different class. Voila, Active Records. Use `->all()` to fetch all objects.

```
$sessions = $db->fetch('SELECT s.* from sessions s, people p WHERE p.access_level = ? AND p.id = s.person_id', array(
	'params' => array(4),
	'class' => 'UserSession',
))->all();
var_dump(get_class($sessions[0])); // UserSession

```

More advanced conditions.

```
$people = $db->select('people', array(
	// Conditions
	'enabled' => 1,
	'age >= ?',
	'age firstname $this->lastname";
	}
}

echo $user->fullname;

```

Properties are cached in the object, so the getter is called only once.

Add relationships with `relate_NAME()`:

```
class User extends db_generic_model {
	function relate_country() {
		return $this->to_one(Country::class, 'country_id');
	}

	function relate_hobbies() {
		return $this->to_many(Hobby::class, 'user_id');
	}

	function relate_groups() {
		return $this->to_many_through(Group::class, 'users_groups', 'user_id', 'group_id');
	}

	function relate_num_groups() {
		return $this->to_count(UserGroup::class, 'user_id');
	}

	function relate_group_ids() {
		return $this->to_many_scalar('group_id', 'users_groups', 'user_id');
	}
}

echo $user->country->name;
print_r($user->hobbies);
print_r($user->groups);
echo $user->num_groups;
print_r($user->group_ids);

```

All primary keys must be `id`. Foreign keys can be anything.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance43

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity74

Established project with proven stability

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

Recently: every ~263 days

Total

29

Last Release

380d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/78549c1dc5c83ec0201c9afc66762c6d5bbf770291b12bae5a7a65350f950dba?d=identicon)[rudiedirkx](/maintainers/rudiedirkx)

---

Top Contributors

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

### Embed Badge

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

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