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

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

mathsgod/light-db
=================

Light-DB ORM

v1.9.1(1w ago)02232MITPHPPHP &gt;=8.2CI passing

Since May 16Pushed 1w ago1 watchersCompare

[ Source](https://github.com/mathsgod/light-db)[ Packagist](https://packagist.org/packages/mathsgod/light-db)[ RSS](/packages/mathsgod-light-db/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (34)Versions (30)Used By (2)

[![GitHub](https://camo.githubusercontent.com/bafb88b2c7d52b0104ecfff0ec02c16e650f965d9433af6e1dbf2479072fa557/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d61746873676f642f6c696768742d6462)](https://github.com/mathsgod/light-db)[![PHP](https://camo.githubusercontent.com/0f16581d1180dbfd4c0e13166ec1267d4ad2f2fab8281ea6d6b284cf5c65d921/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322532422d626c75652e737667)](https://www.php.net/)[![CI](https://github.com/mathsgod/light-db/actions/workflows/tests.yml/badge.svg)](https://github.com/mathsgod/light-db/actions)[![Tests](https://camo.githubusercontent.com/f339b042d7c16706f2e041c7f0891e94ad0071766dab704b622de3c9d1020f7e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d393625323070617373696e672d627269676874677265656e2e737667)](https://github.com/mathsgod/light-db)[![MySQL](https://camo.githubusercontent.com/f17f1a170e938bcd2ad1ef19d3b4b5d514c0ada25ac13b5d521f4acfafafcaa0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d7953514c2d382e302d626c75652e737667)](https://www.mysql.com/)[![MariaDB](https://camo.githubusercontent.com/e4974fae3848cb16128141f59c1d6938d5d2636fb5e3619ae026e6c2cfe7e2dd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d6172696144422d31302e313125323025374325323031312e342d626c75652e737667)](https://mariadb.org/)

Light-DB
========

[](#light-db)

Light-DB is a lightweight PHP ORM/database access layer built on top of Laminas DB, designed for modern PHP 8.2+ applications. It provides an Eloquent-like Active Record experience with support for auto-mapping, dynamic queries, relationship queries, JSON field operations, and pagination — with first-class compatibility for both **MySQL 8.0** and **MariaDB 10.11 / 11.4**.

✨ Features
----------

[](#-features)

- 🚀 **Modern PHP**: Built on PHP 8.2+ features with type declarations and modern PHP syntax
- 🔗 **Multi-Database Support**: Based on Laminas DB — supports MySQL 8.0, MariaDB 10.11/11.4, PostgreSQL, SQLite, SQL Server
- 🧩 **MariaDB-Aware**: Detects MariaDB at runtime and adjusts column metadata (JSON detection, default-value parsing) automatically
- 📦 **Eloquent-Style**: Familiar Active Record pattern with an Eloquent-like API powered by `illuminate/collections`
- 🎯 **Smart Queries**: Complex conditional queries, sorting, grouping, and aggregation functions
- 📄 **Pagination Support**: Built-in Laminas Paginator integration
- 🔄 **JSON Fields**: Native JSON field operations with automatic serialization/deserialization
- 🔗 **Relationship Queries**: Inter-model relationship queries and dynamic property access
- ✅ **CI-Tested**: Automated test matrix on GitHub Actions across PHP 8.2 / 8.3 / 8.4 / 8.5 × MySQL 8.0 / MariaDB 10.11 / MariaDB 11.4

📋 Requirements
--------------

[](#-requirements)

- PHP 8.2 or higher
- PDO extension
- A supported database (tested against):
    - MySQL 8.0
    - MariaDB 10.11 / 11.4

🚀 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require mathsgod/light-db
```

⚙️ Configuration
----------------

[](#️-configuration)

Create a `.env` file in your project root:

```
DATABASE_DRIVER=Pdo_Mysql
DATABASE_HOSTNAME=localhost
DATABASE_PORT=3306
DATABASE_DATABASE=your_database
DATABASE_USERNAME=your_username
DATABASE_PASSWORD=your_password
DATABASE_CHARSET=utf8mb4
```

🎯 Basic Usage
-------------

[](#-basic-usage)

### Defining Models

[](#defining-models)

```
