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

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

roolith/database
================

PHP database driver

1.4.0(6mo ago)2108[1 issues](https://github.com/im4aLL/roolith-database/issues)2MITPHP

Since Aug 22Pushed 6mo ago2 watchersCompare

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

READMEChangelogDependencies (2)Versions (9)Used By (2)

roolith-database
================

[](#roolith-database)

PHP database driver

#### Install

[](#install)

```
composer require roolith/database

```

#### Usage

[](#usage)

```
use Roolith\Store\Database;

$db = new Database();
$db->connect([
    'host' => 'host',
    'name' => 'dbname',
    'user' => 'username',
    'pass' => 'password',
]);

// Get all users
$users = $db->query("SELECT * FROM users")->get();
print_r($users);

// Get all usernames
$usernames = $db->table('users')->select([
    'field' => 'name',
])->get();
print_r($usernames);

// Disconnect
$db->disconnect();
```

##### Select

[](#select)

```
$db->query("SELECT * FROM users")->get();
```

```
$db->table('users')->select([
    'field' => ['name', 'email'],
    'condition' => 'WHERE id > 0',
    'limit' => '0, 10',
    'orderBy' => 'name',
    'groupBy' => 'name',
])->get();
```

##### Insert

[](#insert)

```
$result = $db->table('users')->insert(
    ['name' => 'Brannon Bruen', 'email' => 'bschmeler@pacocha.net']
);

print_r($result->success());
```

Insert data when supplied email `john@email.com` not exists in table `users`:

```
$result = $db->table('users')->insert(
    ['name' => 'John doe', 'email' => 'john@email.com'],
    ['email']
);
```

###### Response:

[](#response)

```
$result->affectedRow();
$result->insertedId();
$result->isDuplicate();
$result->success();
```

##### Update

[](#update)

```
$result = $db->table('users')->update(
    ['name' => 'Habib Hadi', 'email' => 'john@email.com'],
    ['id' => 1]
);
```

or

```
$result = $db->table('users')->update(
    ['name' => 'Habib Hadi', 'email' => 'john@email.com'],
    'id = 1'
);
```

update username if nobody else is using same username

```
$result = $db->table('users')->update(
    ['username' => 'johndoe'],
    ['id' => 4],
    ['username']
);
```

###### Response:

[](#response-1)

```
$result->affectedRow();
$result->isDuplicate();
$result->success();
```

##### Delete

[](#delete)

```
$result = $db->table('users')->delete(['id' => 4]);
```

###### Response:

[](#response-2)

```
$result->affectedRow();
$result->success();
```

##### Connect

[](#connect)

```
$db = new Database();
$db->connect([
    'host' => 'host',
    'name' => 'dbname',
    'user' => 'username',
    'pass' => 'password',
]);
```

or

```
$db = new Database([
   'host' => 'host',
   'name' => 'dbname',
   'user' => 'username',
   'pass' => 'password',
]);
```

##### Disconnect

[](#disconnect)

```
$db->disconnect();
```

##### Others

[](#others)

Search users table with `LIKE` operator

```
$db->table('users')->where('name', '%Hadi%', 'LIKE')->get();
```

Get user by id 1

```
$db->table('users')->find(1);
```

Pluck name and email from users table

```
$db->table('users')->pluck(['name', 'email']);
```

Get total record of users table

```
$db->query("SELECT id FROM users")->count();
```

##### Pagination

[](#pagination)

```
$total = $db->query("SELECT id FROM users")->count();
$result = $db->query("SELECT * FROM users")->paginate([
    'perPage' => 5,
    'pageUrl' => 'http://domain.com',
    'primaryColumn' => 'id',
    'pageParam' => 'page',
    'total' => $total,
]);
```

or

```
$total = $db->query("SELECT id FROM users")->count();
$result = $db->query("SELECT * FROM users")->paginate([
    'perPage' => 5, // default 20
    'total' => $total,
]);
```

```
print_r($result->getDetails());
```

```
{
    "total": 50,
    "perPage": 15,
    "currentPage": 1,
    "lastPage": 4,
    "firstPageUrl": "http://domain.com?page=1",
    "lastPageUrl": "http://domain.com?page=4",
    "nextPageUrl": "http://domain.com?page=2",
    "prevPageUrl": null,
    "path": "http://domain.com",
    "from": 1,
    "to": 15,
    "data":[
        // records
    ]
}

```

##### Debug mode

[](#debug-mode)

```
$db->debugMode()->table('users')->find(1);
```

Note: Once debug-mode is active then it will show query string!

#### Development

[](#development)

```
PHPUnit 9.3.7 by Sebastian Bergmann and contributors.

Database
 ✔ Should construct with config
 ✔ Should construct without config
 ✔ Should connect
 ✔ Should disconnect
 ✔ Should allow raw query
 ✔ Should return first result
 ✔ Should select
 ✔ Should insert
 ✔ Should insert if record not exists
 ✔ Should update
 ✔ Should update if record not exists
 ✔ Should delete
 ✔ Should get result based on where
 ✔ Should get result by find
 ✔ Should pluck by field name
 ✔ Should paginate

Paginate
 ✔ Should get count
 ✔ Should get total
 ✔ Should get total page
 ✔ Should get current page
 ✔ Should get first item
 ✔ Should get last item
 ✔ Should get items
 ✔ Should get first page url
 ✔ Should get last page url
 ✔ Should get next page url
 ✔ Should get prev page url
 ✔ Should get page numbers
 ✔ Should get limit
 ✔ Should get offset
 ✔ Should get details

Time: 00:00.144, Memory: 6.00 MB

OK (31 tests, 41 assertions)

```

###  Health Score

38

—

LowBetter than 84% of packages

Maintenance60

Regular maintenance activity

Popularity12

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85% 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 ~268 days

Recently: every ~368 days

Total

8

Last Release

208d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d3abbd3c37f2c01c0d861dd840f5891d65d182a52410c4fae61ba70274154625?d=identicon)[im4aLL](/maintainers/im4aLL)

---

Top Contributors

[![im4aLL](https://avatars.githubusercontent.com/u/1926302?v=4)](https://github.com/im4aLL "im4aLL (17 commits)")[![hadiAugmedix](https://avatars.githubusercontent.com/u/35101957?v=4)](https://github.com/hadiAugmedix "hadiAugmedix (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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.3k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M543](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M209](/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)
