PHPackages                             erusev/base - 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. erusev/base

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

erusev/base
===========

Simple Database Interface

0.2.0(11y ago)26617015[6 issues](https://github.com/erusev/base/issues)MITPHP

Since Feb 22Pushed 2y ago14 watchersCompare

[ Source](https://github.com/erusev/base)[ Packagist](https://packagist.org/packages/erusev/base)[ Docs](https://github.com/erusev/base)[ RSS](/packages/erusev-base/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Base
----

[](#base)

Base is a simple library that makes it easier to work with databases in PHP.

I have been using it since 2012 and I felt like it is about time I share it.

### Features

[](#features)

- Simple
- Intuitive
- Independent
- Secure
- Tested in 5.3, 5.4, 5.5, 5.6, 7 and [HHVM](http://hhvm.com/)

### Installation

[](#installation)

Include both `Base.php` and `Collection.php` or install [the composer package](https://packagist.org/packages/erusev/base).

### Examples

[](#examples)

Connect to a database:

```
# the constructor takes the same parameters as the PDO constructor
$Base = new \Base\Base('mysql:host=localhost;dbname=example', 'username', 'password');
```

Work with records:

```
# read user 1
$Base->readItem('user', 1);
# update the username of user 1
$Base->updateItem('user', 1, ['username' => 'john.doe']);
# create a user
$Base->createItem('user', ['username' => 'jane.doe', 'email' => 'jane@example.com']);
# delete user 1
$Base->deleteItem('user', 1);
```

Work with collections:

```
# read all users
$Base->find('user')->read();
# read the users that are marked as verified in a desc order
$Base->find('user')->whereEqual('is_verified', 1)->orderDesc('id')->read();
# read the user with the most reputation
$Base->find('user')->limit(1)->orderDesc('reputation')->readRecord();
# mark users 1 and 3 as verified
$Base->find('user')->whereIn('id', [1, 3])->update(['is_verified' => 1]);
# count the users that don't have a location
$Base->find('user')->whereNull('location')->count();
# plain sql conditions are also supported
$Base->find('user')->where('is_verified = ?', [1])->read();
```

Handle relationships:

```
# read the users that have a featured post
$Base->find('user')->has('post')->whereEqual('post.is_featured', 1)->read();
# read the posts of user 1
$Base->find('post')->belongsTo('user')->whereEqual('user.id', 1)->read();
# read the posts that are tagged "php"
$Base->find('post')->hasAndBelongsTo('tag')->whereEqual('tag.name', 'php')->read();
# unconventional FK names are also supported
$Base->find('user')->has('post', 'author_id')->whereEqual('user.id', 1)->read();
```

Execute queries:

```
# read all users
$Base->read('SELECT * FROM user');
# read user 1
$Base->readRecord('SELECT * FROM user WHERE id = ?', [1]);
# read the username of user 1
$Base->readField('SELECT username FROM user WHERE id = ?', [1]);
# read all usernames
$Base->readFields('SELECT username FROM user');
# update all users
$Base->update('UPDATE user SET is_verified = ?', [1]);
```

### Notes

[](#notes)

- Not tested on other RDBMSs than MySQL
- Relationship methods assume that table names are singular - ex: `user` instead of `users`
- Relationship methods assume that FK names end in `_id` - use `$fkEnding` to customize

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99.3% 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 ~66 days

Total

2

Last Release

4037d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1342a4632975df49238fe2575a17c1494d5176b03c894075bd0c973730bcfc33?d=identicon)[erusev](/maintainers/erusev)

---

Top Contributors

[![erusev](https://avatars.githubusercontent.com/u/184170?v=4)](https://github.com/erusev "erusev (139 commits)")[![hkdobrev](https://avatars.githubusercontent.com/u/506129?v=4)](https://github.com/hkdobrev "hkdobrev (1 commits)")

---

Tags

databaseormpdo

### Embed Badge

![Health badge](/badges/erusev-base/health.svg)

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

###  Alternatives

[bephp/activerecord

micro activerecord library in PHP(only 400 lines with comments), support chain calls and relations(HAS\_ONE, HAS\_MANY, BELONGS\_TO).

1202.1k2](/packages/bephp-activerecord)[flightphp/active-record

Micro Active Record library in PHP, support chain calls, events, and relations.

163.0k](/packages/flightphp-active-record)

PHPackages © 2026

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