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

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

samsmithkruz/database-handler
=============================

A reusable database handler supporting SQL &amp; NoSQL.

1.0.0(1y ago)01MITPHPPHP &gt;=7.4 || ^8.0CI passing

Since Apr 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/samsmithKruz/database_handler)[ Packagist](https://packagist.org/packages/samsmithkruz/database-handler)[ Docs](https://github.com/samsmithKruz/database_handler)[ RSS](/packages/samsmithkruz-database-handler/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Database Handler
================

[](#database-handler)

*A reusable PHP database handler supporting SQL (MySQL, PostgreSQL) and NoSQL (MongoDB, Redis).*

[![Packagist](https://camo.githubusercontent.com/7e3bddebd04a53d0bb00fba7e28b294f035672a27b2450e34c26c38c9dd5f7c8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616d736d6974686b72757a2f64617461626173652d68616e646c6572)](https://camo.githubusercontent.com/7e3bddebd04a53d0bb00fba7e28b294f035672a27b2450e34c26c38c9dd5f7c8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616d736d6974686b72757a2f64617461626173652d68616e646c6572) [![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)

Overview
--------

[](#overview)

`database-handler` is a lightweight, flexible, and reusable PHP package that provides a unified interface for interacting with both **SQL** and **NoSQL** databases.
It simplifies database operations and supports **MySQL, PostgreSQL, MongoDB, and Redis**, making it ideal for modern web applications.

---

Features
--------

[](#features)

✅ **Multi-Database Support** - Works with MySQL, PostgreSQL, MongoDB, and Redis.
✅ **Unified API** - Consistent methods across different database types.
✅ **PSR-4 Autoloading** - Easy to integrate into any PHP project.
✅ **Flexible Queries** - Raw queries, transactions, and batch operations supported.
✅ **Exception Handling** - Catches and logs errors gracefully.
✅ **Lightweight &amp; Fast** - Designed for efficiency with minimal dependencies.

---

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

[](#installation)

Install via **Composer**:

```
composer require samsmithkruz/database-handler
```

---

Configuration
-------------

[](#configuration)

Create a database configuration array based on your preferred database.

### MySQL / PostgreSQL Example

[](#mysql--postgresql-example)

```
use SamsmithKruz\Database\Database;

$config = [
    'driver'   => 'mysql', // or 'pgsql' for PostgreSQL
    'host'     => '127.0.0.1',
    'port'     => 3306,
    'database' => 'test_db',
    'username' => 'root',
    'password' => '',
    'charset'  => 'utf8mb4'
];

$db = new Database($config);
```

### MongoDB Example

[](#mongodb-example)

```
use SamsmithKruz\Database\Database;

$config = [
    'driver'   => 'mongodb',
    'uri'      => 'mongodb://127.0.0.1:27017',
    'database' => 'test_db'
];

$db = new Database($config);
```

### Redis Example

[](#redis-example)

```
use SamsmithKruz\Database\Database;

$config = [
    'driver'   => 'redis',
    'scheme'   => 'tcp', // Optional
    'host' => '127.0.0.1',
    'timeout'   => '0.0', // Seconds
    'port' => 6379
];

$db = new Database($config);
```

---

Usage Guide
-----------

[](#usage-guide)

### Insert Data

[](#insert-data)

```
$data = ['name' => 'John Doe', 'email' => 'john@example.com'];
$db->insert('users', $data);
```

### Find One Record

[](#find-one-record)

```
$user = $db->findOne('users', ['email' => 'john@example.com']);
print_r($user);
```

### Find Multiple Records

[](#find-multiple-records)

```
$users = $db->findMany('users', ['status' => 'active']);
```

### Update Data

[](#update-data)

```
$db->updateOne('users', ['email' => 'john@example.com'], ['status' => 'inactive']);
```

### Delete Data

[](#delete-data)

```
$db->deleteOne('users', ['email' => 'john@example.com']);
```

### Raw Query (MongoDB)

[](#raw-query-mongodb)

```
$query = [['$match' => ['status' => 'active']]];
$results = $db->rawQuery('users', $query);
```

---

Running Tests
-------------

[](#running-tests)

Ensure you have **PHPUnit** installed and run:

```
vendor/bin/phpunit --configuration phpunit.xml
```

---

Contributing
------------

[](#contributing)

We welcome contributions! 🚀

1. Fork the repository
2. Create a new feature branch (`git checkout -b feature-name`)
3. Make your changes
4. Submit a pull request

See [`CONTRIBUTING.md`](CONTRIBUTING.md) for more details.

---

License
-------

[](#license)

This package is licensed under the **MIT License**.
See the [`LICENSE`](LICENSE) file for details.

---

Author
------

[](#author)

👤 **Samuel Benny (Smith Kruz)**
🔗 GitHub: [samsmithkruz](https://github.com/samsmithkruz)
🔗 LinkedIn: [smithkruz](https://linkedin.com/in/smithkruz)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance46

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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

Unknown

Total

1

Last Release

412d ago

### Community

Maintainers

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

---

Top Contributors

[![samsmithKruz](https://avatars.githubusercontent.com/u/85261000?v=4)](https://github.com/samsmithKruz "samsmithKruz (10 commits)")

---

Tags

phpdatabaseormmysqlpostgresqlredismongodbdatabase handler

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58523.9M36](/packages/scienta-doctrine-json-functions)[moharrum/laravel-adminer

Adminer database management tool for your Laravel application.

451.0k](/packages/moharrum-laravel-adminer)[ramadan/easy-model

A Laravel package for enjoyably managing database queries.

101.6k](/packages/ramadan-easy-model)

PHPackages © 2026

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