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

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

miladm/orm
==========

basic and lite orm for php

4.0.9(3y ago)02161Apache-2.0PHP

Since Sep 16Pushed 3y ago1 watchersCompare

[ Source](https://github.com/MiladMohebnia/PHP_ORM)[ Packagist](https://packagist.org/packages/miladm/orm)[ RSS](/packages/miladm-orm/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (25)Used By (1)

Database (table) introduction
=============================

[](#database-table-introduction)

This hook takes care of everything you need with database and currently it works with **MySQL** database. With the use of **PDO** communication, it will lower the threat of SQL-injection to almost zero.

Configuration and Installation
==============================

[](#configuration-and-installation)

create
------

[](#create)

For each table you have to create a Class extends from `Table` class.

```
use miladm\table\Table;

class User extends Table {

}
```

there are abstract methods you have to config as below

methoddescriptionconnectionhere we register the database connection and configurationstableNamethe name of current table in string```
class User extends Table {
	public function connection() {
		return new MainConnection;
	}

	public function tableName() {
		return 'user';
	}
}
```

setup actions before using the table
------------------------------------

[](#setup-actions-before-using-the-table)

there's a method called `init` to setup actions before using this table;

```
	public function init()
	{
		$this->leftJoin( .... );
	}
```

Connection Class
----------------

[](#connection-class)

```
use miladm\table\Connection;

class MainConnection extends Connection
{
    public $host = "127.0.0.1";
    public $databaseName = "sample";
    public $user = 'root';
    public $password = 'root';
}
```

here's the structure of creating connection and to assign a table to a connection

```
class User extends Table {
	...

	public function connection() {
		return new MainConnection;
	}

	....
}
```

**NOTE:** by default the key name is `id` so if it's the same with your table key name you don't have to set it.

set default Key
---------------

[](#set-default-key)

```
    public function key()
    {
        return 'id';
	}
```

you can change `'id'` as you wish and your database structure is.

Query
=====

[](#query)

To create the query you need to create a function of your table then create the query.

```
$userTable = new user;
$userTable->select();// this will select all records from user table

// equal Query : SELECT * FROM `user` WHERE 1
```

query methods
-------------

[](#query-methods)

methodparametersdescriptiontracestate(boolean)will return the query string and won't run query just to tracesafeModestate(boolean)queryquery:string, data?:optionalyou can run query directly into tableinsertdata:arrayinsert data into tablewherecondition: string\\arrayset condition for current query (update or delete)deletedelete current query (condition required)selectcolumnList:array\\stringselects from tablecountreturns number of resultsorderDesccolumn:string\\arraysetup desc orderordercolumn:string\\array, asc?:booleansetup order of current querygroupcolumn:stringacts as group by queryhavingcondition: string\\arrayacts as having querylimitcount:int, startPoint?:intmake limitation for query and you can do paginationfetchArrayfetch the results as arraycheckIfFetchArrayreturns boolean if we are expecting arrayfetchObjectfetch results as objectcheckIfFetchObjectreturn boolean if we are expecting object as resultnamereturn this table nameasname:stringset a secondary name for table as aliascoverNamename:stringworks the same as `as` methodjointable:Table, mapping?:arrayjoin this table to other table returns Table object with joinleftJointable:Table, mapping?:arrayleft join table to other table returns Table object with leftjoininit\_jointable:Table, mapping?:arraydo join effect current objectinit\_leftJointable:Table, mapping?:arraydo left join effect current objectgetRelationreturn relation object of current objectResults data object
===================

[](#results-data-object)

If you fetch data as object there will be some features assigned to result data object.

update data
-----------

[](#update-data)

you can update data of current result and call `->save()` on results data object and update will happen on database.

```
$UserModel = new User();
$userData = $userModel->where(['id' => 1])->select();
echo $userData[0]->name; // its alex for example
$userData[0]->name = 'jack'; // variable updated but not saved on database
$userData[0]->save(); // now the change has updated the database
```

**note**

> documentation is in progress but code talks itself. checkout the code for more.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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

Every ~43 days

Recently: every ~184 days

Total

21

Last Release

1201d ago

Major Versions

3.9.9 → 4.0.02021-01-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/22d33b0e34bc66cae7ab5a979b15f2975bb87dd73d1cfa2255dae95302799d75?d=identicon)[MiladM](/maintainers/MiladM)

---

Top Contributors

[![MiladMohebnia](https://avatars.githubusercontent.com/u/6062074?v=4)](https://github.com/MiladMohebnia "MiladMohebnia (43 commits)")

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/miladm-orm/health.svg)](https://phpackages.com/packages/miladm-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)
