PHPackages                             or81/eloquent - 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. or81/eloquent

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

or81/eloquent
=============

A lightweight and versatile PHP database class that supports both MySQL and SQLite, providing an easy-to-use interface for common database operations such as `SELECT`, `INSERT`, `UPDATE`, and `DELETE`.

00PHP

Since Aug 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/OR81/eloquent)[ Packagist](https://packagist.org/packages/or81/eloquent)[ RSS](/packages/or81-eloquent/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Database Class
==================

[](#php-database-class)

A lightweight and versatile PHP database class that supports both MySQL and SQLite, providing an easy-to-use interface for common database operations such as `SELECT`, `INSERT`, `UPDATE`, and `DELETE`.

Features
--------

[](#features)

- **Multiple Database Support**: Easily switch between MySQL and SQLite by changing the configuration.
- **Automatic Table Naming**: Automatically determines the table name based on the class name, with an option to override it.
- **Flexible Query Builder**: Chain methods for `WHERE`, `JOIN`, `ORDER BY`, `LIMIT`, and more.
- **CRUD Operations**: Simplified methods for creating, reading, updating, and deleting records.
- **Aggregation Functions**: Includes `MIN`, `MAX`, and `COUNT` functions for efficient data retrieval.
- **File Creation for SQLite**: Automatically creates the SQLite database file if it doesn't exist.

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

[](#installation)

1. Clone this repository to your project:

    ```
    git clone https://github.com/OR81/eloquent.git
    ```
2. Include the `DB` class in your project:

    ```
    require_once 'path/to/DB.php';
    ```
3. Configure the class for your database:

    - **MySQL** (default): ```
        $db = new \Config\DB();
        ```
    - **SQLite**: ```
        $db = new \Config\DB();
        $db->driver = 'sqlite';
        $db->sqlitePath = 'path/to/your/database.sqlite';
        ```

Usage
-----

[](#usage)

### Selecting Data

[](#selecting-data)

- **Basic Select**:

    ```
    $results = $db->table('users')->select('*')->get();
    ```
- **With Where Clause**:

    ```
    $results = $db->table('users')->where('age', '>', 25)->get();
    ```
- **With Join**:

    ```
    $results = $db->table('users')
                  ->join('posts', 'users.id', 'posts.user_id')
                  ->select('users.name, posts.title')
                  ->get();
    ```
- **Aggregation**:

    ```
    $maxAge = $db->table('users')->max('age');
    ```

### Inserting Data

[](#inserting-data)

- **Single Insert**:

    ```
    $user = $db->table('users')->insert([
        'name' => 'John Doe',
        'email' => 'john@example.com'
    ]);
    ```
- **Multiple Inserts**:

    ```
    $db->table('users')->insertMultiple([
        ['name' => 'Alice', 'email' => 'alice@example.com'],
        ['name' => 'Bob', 'email' => 'bob@example.com']
    ]);
    ```

### Updating Data

[](#updating-data)

- **Update Record**: ```
    $db->table('users')
       ->where('id', 1)
       ->update(['name' => 'John Smith']);
    ```

### Deleting Data

[](#deleting-data)

- **Delete Record**: ```
    $db->table('users')->where('id', 1)->delete();
    ```

### Counting Records

[](#counting-records)

- **Count All Records**: ```
    $userCount = $db->table('users')->count();
    ```

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

[](#configuration)

The `DB` class can be configured by modifying the following properties:

- **MySQL Configuration**:

    - `$driver = 'mysql';` (default)
    - `$host = 'localhost';`
    - `$dbName = 'your_database';`
    - `$username = 'your_username';`
    - `$password = 'your_password';`
- **SQLite Configuration**:

    - `$driver = 'sqlite';`
    - `$sqlitePath = 'path/to/your/database.sqlite';`

License
-------

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.

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

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request or open an Issue on GitHub.

Contact
-------

[](#contact)

For any inquiries or support, please reach out to .

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity17

Early-stage or recently created project

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/543964ede5541c9a42214d692d157481649f91ae97f15f77b885ef8cc7b923c1?d=identicon)[or81](/maintainers/or81)

### Embed Badge

![Health badge](/badges/or81-eloquent/health.svg)

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

###  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)
