PHPackages                             octacondeveloper/php-orm - 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. octacondeveloper/php-orm

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

octacondeveloper/php-orm
========================

This is a light weight ORM for core PHP applications that supports MySQL, Postgres and Sqlite database engine out of the box.

0.0.1(3y ago)024MITPHP

Since Mar 15Pushed 3y ago1 watchersCompare

[ Source](https://github.com/OctaconDeveloper/PHP-ORM)[ Packagist](https://packagist.org/packages/octacondeveloper/php-orm)[ RSS](/packages/octacondeveloper-php-orm/feed)WikiDiscussions dev Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

PHP-ORM
=======

[](#php-orm)

This is a light weight ORM for core PHP applications that supports MySQL, Postgres and Sqlite database engine out of the box.

Badges
------

[](#badges)

[![MIT License](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://choosealicense.com/licenses/mit/)[![GPLv3 License](https://camo.githubusercontent.com/da9c3abfd62c32a94031c3a382cb7c85dbd4cede411416837adfe6b8fda05ba1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d47504c25323076332d79656c6c6f772e737667)](https://opensource.org/licenses/)[![AGPL License](https://camo.githubusercontent.com/aed477ac82de60abd644cfa7c9d381eebe9a00d5d32168644f7e6d2a23957d1b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4147504c2d626c75652e737667)](http://www.gnu.org/licenses/agpl-3.0)

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

[](#installation)

Install PHP-ORM with composer

```
  composer require octacondeveloper/php-orm
```

Env
---

[](#env)

```
  ## MYSQL Connection Example
    DB_CONNECTION=mysql
    DB_HOST=
    DB_PORT=
    DB_DATABASE=
    DB_USERNAME=
    DB_PASSWORD=

    # ## POSTGRES Connection Example
    DB_CONNECTION=postgresql
    DB_HOST=127.0.0.1
    DB_PORT=5432
    DB_DATABASE=
    DB_USERNAME=
    DB_PASSWORD=

    ## SQLite Connection Example
    DB_CONNECTION=sqlite
    DB_PATH="test_db_two.sqlite"
```

Usage/Examples
--------------

[](#usageexamples)

```
use PhpOrm\Query;

$result  = Query::table('users')->all();
```

Or You can use it as a Model Extension

```
use PhpOrm\Model;

class User extends Model {

    //this is optional if your table name differs from the class name
    protected $table = 'users';
}
```

Then in your class you can call the User Class with the Query methods

```
use `Your-class-namespace`

$result  = User::all();
```

Documentation
-------------

[](#documentation)

PHP-ORM provides you with two distinct methods of interactions with methods. Which can be through

### Query

[](#query)

This options allow to specify the table name directly while making the calls and it has several methods. A quick example of it usage is

```
use PhpOrm\Query;

$result  = Query::table('users')->all();

```

#### Available methods

[](#available-methods)

#### insert(array $data)

[](#insertarray-data)

Create a new record into the selected table

```
use PhpOrm\Query;

$data = [
    "name" => "Jil Harrys",
    "sex" => "Male"
];
$result  = Query::table('users')->insert($data);

```

#### insertBulk(array $data);

[](#insertbulkarray-data)

Insert bulk records at once

```
use PhpOrm\Query;

$data = [
    [
        "name" => "Jil Harrys",
        "sex" => "Male"
    ],
    [
        "name" => "Lionel Messi",
        "sex" => "Female"
    ],
    [
        "name" => "John Does",
        "sex" => "Male"
    ],
];
$result  = Query::table('users')->insertBulk($data);

```

#### all();

[](#all)

Fetch all records on the table

```
use PhpOrm\Query;

$result  = Query::table('users')->all();

```

#### first();

[](#first)

Fetch the first record on the table

```
use PhpOrm\Query;

$result  = Query::table('users')->first();

```

#### last(string $column);

[](#laststring-column)

Fetch the last record on the datable, If a column is not provided, it would order it based on the primaryKey or based on the first availablecolumn on the table

```
use PhpOrm\Query;

$result  = Query::table('users')->last();
$result  = Query::table('users')->last('updated_at');

```

#### rawQuery(string $sqlQuery);

[](#rawquerystring-sqlquery)

This allows you to pass direct sql string to the Query instance

```
use PhpOrm\Query;

$result  = Query::rawQuery("SELECT * FROM users");

```

#### where(string $column, string $operand, string $value);

[](#wherestring-column-string-operand-string-value)

Add a query condition

```
use PhpOrm\Query;

$result  = Query::table('users')->where('sex','harrys');
$result  = Query::table('users')->where('sex',,'!=','harrys');

```

#### andWhere(string $column, string $operand, string $value);

[](#andwherestring-column-string-operand-string-value)

Add another compulsory query condition, this comes after an initial "where" method has been called

```
use PhpOrm\Query;

$result  = Query::table('users')->andWhere('sex','harrys');
$result  = Query::table('users')->andWhere('sex',,'!=','harrys');

```

#### orWhere(string $column, string $operand, string $value);

[](#orwherestring-column-string-operand-string-value)

Add another optional query condition, this comes after an initial "where" method has been called

```
use PhpOrm\Query;

$result  = Query::table('users')->orWhere('sex','harrys');
$result  = Query::table('users')->orWhere('sex',,'!=','harrys');

```

#### orderBy(string $column, string $order);

[](#orderbystring-column-string-order)

Order records based on column either in ASC or DESC. Default order is ASC

```
use PhpOrm\Query;

$result  = Query::table('users')->orderBy('id','desc');
$result  = Query::table('users')->orderBy('id');

```

#### count(string $column = null, string $value, string $operand);

[](#countstring-column--null-string-value-string-operand)

Counts the number of records available on the table based on provided column and condition. If no parameters are passed, it count count the total records without any condition

```
use PhpOrm\Query;

$result  = Query::table('users')->count();
$result  = Query::table('users')->count('sex','male');

```

#### max(string $column);

[](#maxstring-column)

Get the maximum

```
use PhpOrm\Query;

$result  = Query::table('users')->min('score');

```

#### min(string $column);

[](#minstring-column)

Get the minimum

```
use PhpOrm\Query;

$result  = Query::table('users')->min('score');

```

#### update(array $data);

[](#updatearray-data)

Update a record

```
use PhpOrm\Query;

$result  = Query::table('users')->where('id','233')->update([
    "sex" => "female"
]);

```

#### delete();

[](#delete)

Delete a record

```
use PhpOrm\Query;

$result  = Query::table('users')->where('id','233')->delete();

$result  = Query::table('users')->delete();

```

#### begingTransaction();

[](#begingtransaction)

Begin a transaction

```
use PhpOrm\Query;

$result  = Query::table('users')->begingTransaction();

```

#### commitTransaction();

[](#committransaction)

Commit a transaction

```
use PhpOrm\Query;

$result  = Query::table('users')->commitTransaction();

```

#### rollbackTransaction();

[](#rollbacktransaction)

Rollback a transaction

```
use PhpOrm\Query;

$result  = Query::table('users')->rollbackTransaction();

```

#### transaction($transaction);

[](#transactiontransaction)

Start a DB trabsaction session

```
use PhpOrm\Query;

$result  = Query::table('users')->transaction(function(){
    $result  = Query::table('users')->where('id','233')->delete();

$result  = Query::table('users')->delete();
});

```

#### withOne(string $table, string $foreignKey, string $primaryKey = 'id')

[](#withonestring-table-string-foreignkey-string-primarykey--id)

Fetch a one to one model relationship between two models

```
use PhpOrm\Query;

$result  = Query::table('users')->withOne('files','user_id','id');

```

#### withMany(string $table, string $foreignKey, string $primaryKey = 'id')

[](#withmanystring-table-string-foreignkey-string-primarykey--id)

Fetch a one to many model relationship between two models

```
use PhpOrm\Query;

$result  = Query::table('users')->withOne('files','user_id','id');

```

### Model

[](#model)

The Model approach allows you to create a class for your table and extends the model base class. This allows you to have other custom SQL related transaction in your class. It can used as follows:

```
use PhpOrm\Model;
class User extends Model{
    protected $table= 'users';
}

```

Defining the table variable is optional. By default the Package gets your class name and assumes the corresponding table name to it. Take for example

```
If the class name is "User", the assumption is that the table name is "users", same for "Student" and "students". But if this assumption is wrong, kindly set the value of the protected $table to override the default table name assumptions.

```

#### Available methods

[](#available-methods-1)

#### insert(array $data)

[](#insertarray-data-1)

Create a new record into the selected table

```

$data = [
    "name" => "Jil Harrys",
    "sex" => "Male"
];
$result  = User::insert($data);

```

#### insertBulk(array $data);

[](#insertbulkarray-data-1)

Insert bulk records at once

```

$data = [
    [
        "name" => "Jil Harrys",
        "sex" => "Male"
    ],
    [
        "name" => "Lionel Messi",
        "sex" => "Female"
    ],
    [
        "name" => "John Does",
        "sex" => "Male"
    ],
];
$result  = User::insertBulk($data);

```

#### all();

[](#all-1)

Fetch all records on the table

```

$result  = User::all();

```

#### first();

[](#first-1)

Fetch the first record on the table

```

$result  = User::first();

```

#### last(string $column);

[](#laststring-column-1)

Fetch the last record on the datable, If a column is not provided, it would order it based on the primaryKey or based on the first availablecolumn on the table

```

$result  = User::last();
$result  = User::last('updated_at');

```

#### where(string $column, string $operand, string $value);

[](#wherestring-column-string-operand-string-value-1)

Add a query condition

```

$result  = User::where('sex','harrys');
$result  = User::where('sex',,'!=','harrys');

```

#### andWhere(string $column, string $operand, string $value);

[](#andwherestring-column-string-operand-string-value-1)

Add another compulsory query condition, this comes after an initial "where" method has been called

```

$result  = User::andWhere('sex','harrys');
$result  = User::andWhere('sex',,'!=','harrys');

```

#### orWhere(string $column, string $operand, string $value);

[](#orwherestring-column-string-operand-string-value-1)

Add another optional query condition, this comes after an initial "where" method has been called

```

$result  = User::orWhere('sex','harrys');
$result  = User::orWhere('sex',,'!=','harrys');

```

#### orderBy(string $column, string $order);

[](#orderbystring-column-string-order-1)

Order records based on column either in ASC or DESC. Default order is ASC

```

$result  = User::orderBy('id','desc');
$result  = User::orderBy('id');

```

#### count(string $column = null, string $value, string $operand);

[](#countstring-column--null-string-value-string-operand-1)

Counts the number of records available on the table based on provided column and condition. If no parameters are passed, it count count the total records without any condition

```

$result  = User::count();
$result  = User::count('sex','male');

```

#### max(string $column);

[](#maxstring-column-1)

Get the maximum

```

$result  = User::min('score');

```

#### min(string $column);

[](#minstring-column-1)

Get the minimum

```

$result  = User::min('score');

```

#### update(array $data);

[](#updatearray-data-1)

Update a record

```

$result  = User::where('id','233')->update([
    "sex" => "female"
]);

```

#### delete();

[](#delete-1)

Delete a record

```

$result  = User::where('id','233')->delete();

$result  = User::delete();

```

#### withOne(string $table, string $foreignKey, string $primaryKey = 'id')

[](#withonestring-table-string-foreignkey-string-primarykey--id-1)

Fetch a one to one model relationship between two models

```

$result  = User::withOne('files','user_id','id')->first();
$result  = User::withOne('files','user_id','id')->all();

```

#### withMany(string $table, string $foreignKey, string $primaryKey = 'id')

[](#withmanystring-table-string-foreignkey-string-primarykey--id-1)

Fetch a one to many model relationship between two models

```

$result  = User::withOne('files','user_id','id')->first();
$result  = User::withOne('files','user_id','id')->all();

```

### Method Chaining

[](#method-chaining)

The package allows method chaining as most of the methods wont return a result until it's chained to certian methods.

```
use PhpOrm\Query;

$query = Query::table('cryptos')->where("name","Harrys")->orWhere("symbol","ETH")->orderBy("name", "asc")->take(2)->min("exchange_rate_dollar");

$query = Query::table('cryptos')->where("name","Harrys")->orWhere("symbol","ETH")->orderBy("name", "asc")->take(2)->first();

$query = Crypto::where("name","Harrys")->orWhere("symbol","ETH")->orderBy("name", "asc")->take(2)->min("exchange_rate_dollar");

$query = Crypto::where("name","Harrys")->orWhere("symbol","ETH")->orderBy("name", "asc")->take(2)->first();

```

Authors
-------

[](#authors)

- [@octaconDeveloper](https://github.com/octacondeveloper)

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

[](#contributing)

Contributions are always welcome! This is an Open Source library and Pull Requests would be extremely welcome.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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

1157d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/40143466?v=4)[Harrys Jil](/maintainers/OctaconDeveloper)[@OctaconDeveloper](https://github.com/OctaconDeveloper)

---

Top Contributors

[![OctaconDeveloper](https://avatars.githubusercontent.com/u/40143466?v=4)](https://github.com/OctaconDeveloper "OctaconDeveloper (11 commits)")

### Embed Badge

![Health badge](/badges/octacondeveloper-php-orm/health.svg)

```
[![Health](https://phpackages.com/badges/octacondeveloper-php-orm/health.svg)](https://phpackages.com/packages/octacondeveloper-php-orm)
```

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