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

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

legomolina/simple-orm
=====================

SimpleORM is a little ORM based on PHP

2.0.1(9y ago)187.3k—1.2%3[1 issues](https://github.com/legomolina/simple-orm/issues)MITPHPPHP &gt;=7.0

Since Oct 24Pushed 4y ago1 watchersCompare

[ Source](https://github.com/legomolina/simple-orm)[ Packagist](https://packagist.org/packages/legomolina/simple-orm)[ RSS](/packages/legomolina-simple-orm/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)DependenciesVersions (24)Used By (0)

SimpleORM
=========

[](#simpleorm)

SimpleORM is a little object-relational mapping library written in PHP. This ORM fits me perfect but probably is too small for your projects so you can fork it and improve it or send me a pull request so I can merge changes :D

### Installation

[](#installation)

SimpleORM is hosted in packagist so you can get it from [Composer](https://getcomposer.org/ "Composer")

```
composer require legomolina/simple-orm

```

### Configure

[](#configure)

Require the Composer autoload in your index:

```
require '../vendor/autoload.php';
```

Create your first model:

```
use \SimpleORM\Model;

class MyModel extends Model
{
    //Select the table which the model references
    protected static function getTableName()
    {
        return 'my_table';
    }
    //OPTIONAL. Select the id field for the table. Default: 'id'
    protected static function getTableId()
    {
        return 'my_table_id';
    }

    //Custom methods for this model

    //public static function myMethod(my_params) { }
}
```

Call config method from Model to pass mysqli connection params

```
\SimpleORM\Model::config(array(
    'name' => 'my_database_name',
    'user' => 'my_user',
    'pass' => '*******',
    'host' => 'my_host',
    'charset' => 'charset'
));
```

And you are ready to use SimpleORM!

### Usage

[](#usage)

#### Quick access methods

[](#quick-access-methods)

SimpleORM has quick select methods to agilize common queries. If you want to select all from your table you don't need to type

```
$result = MyModel::query()->select('*')->execute();
```

Just use `::all()` method from `\SimpleORM\Model`:

```
$result = MyModel::all()->execute();
```

Also you can find the last value of any field of your table simply calling `::getLastValue($field)` from `\SimpleORM\Model` :

```
$result = MyModel::getLastValue('my_field');
```

This is useful when you need the last id of your table to insert a new register when not using autoincrement.

Finally you can retrieve the register with *n* id with `::findId($id)` from `\SimpleORM\Model`:

```
$result = MyModel::findId(12);
```

#### Select queries ([See quick access](#q_access))

[](#select-queries-see-quick-access)

If you want to select all data from your table.

```
$result = MyModel::query()->select('*')->execute();
```

If you want to add conditions. This creates a simple where (WHERE field operator value)

```
$result = MyModel::all()->where()->andFilter("field", "operator", "value")->execute();
```

If you want some conditions you can join them with AND (WHERE field operator value AND field\_2 operator\_2 value\_2).

```
$result = MyModel::all()->where()->andFilter([["field", "operator", "value"], ["field_2", "operator_2", "value_2"]])->execute();
```

Join them with or (WHERE field operator value AND field\_2 operator\_2 value\_2)

```
$result = MyModel::all()->where()->orFilter([["field", "operator", "value"], ["field_2", "operator_2", "value_2"]])->execute();
```

If you want to combine both (WHERE (field operator value AND field\_2 operator\_2 value\_2) OR (field\_3 operator\_3 value\_3))

```
$result = MyModel::all()->where()->andFilter([["field", "operator", "value"], ["field_2", "operator_2", "value_2"]])->or()->orFilter("field_3", "operator_3", "value_3")->execute();
```

Also you can check for NULL values (WHERE field IS NULL)

```
$result = MyModel::all()->where()->isNull("field")->execute();
```

Or you can negate (WHERE (field operator value) OR NOT (field\_2 operator\_2 value\_2))

```
$result = MyModel::all()->where()->andFilter("field", "operator", "value")->or()->not()->andFilter("field_2", "operator_2", "value_2")->execute();
```

If you don't want to select all fields.

```
$result = MyModel::query()->select('field_1', 'field_2')->where('field', '=', 'value')->execute();
```

If you want to order results by any field.

```
$result = MyModel::all()->order('field', 'ASC')->execute();
$result = MyModel::all()->order(['field_1', 'field_2'], ['ASC', 'DESC'])->execute();
```

If you want to limit the results returned.

```
$result = MyModel::all()->get(1)->execute(); //get 1 without offset
$result = MyModel::all()->get(1, 2)->execute(); //get 1 with offset 2
```

#### Data manipulation

[](#data-manipulation)

If you want to insert values.

```
$insert = array('field' => 'value', 'field' => 'value');
$result = MyModel::query()->insert($insert)->execute();

//$result => true if insertion is correct, false otherwise
```

If you want to delete items.

```
$result = MyModel::query()->delete()->where('field', '=', 'value')->execute(); //important use where() with delete()

//$result => true if delete is correct, false otherwise
```

If you want to update items.

```
$update = array('field' => 'value', 'field' => 'value');
$result = MyModel::query()->update($update)->where('field', '=', 'value')->execute(); //important use where() with update()

//$result => true if update is correct, false otherwise
```

### Working with ResultSet

[](#working-with-resultset)

ResultSet is a handler class for Select queries. It allows you to loop through results, find value or checks if exists some field.

#### Getting values from result

[](#getting-values-from-result)

Easiest way doing this is with ResultSet-&gt;loop() method inside while loop.

```
while($result->loop()) {
    $field_1 = $result->table_field_1;
    $field_2 = $result->table_field_2;

    ...

    $field_n = $result->table_field_n;

    //do something with the values
}
```

ResultSet-&gt;loop() loops through all registers in the ResultSet and each iteration it loads next register values.

You can also go to *n* register executing

```
$result->goToRegister(n);

$result->table_field_1;
$result->table_field_2;
```

Or you can loop manually with

```
$result->first(); //loads first register
$result->next();  //loads next register if exists, otherwise it will return false
$result->prev();  //loads previous register if exists, otherwise it will return false
$result->last();  //loads last register
```

You can check manually if the current register is the first or the last.

```
$result->isFirst(); //true | false
$result->isLast();  //true | false
```

#### Search for a value

[](#search-for-a-value)

With ResultSet you can search for a specific value in all results from database and return the register it belongs to.

```
$result->find('table_field', 'find_this_value'); //returns false if doesn't find anything
```

Also you can know if a field exists.

```
$result->fieldExists('table_field'); //true if exists, false otherwise
```

And finally you can search a value from ALL registers. It will return the first register that founds with this value

```
$result->findValue('find_this_value');
```

### License

[](#license)

SimpleORM is licensed under the MIT license. See License File for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity68

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 ~7 days

Recently: every ~35 days

Total

22

Last Release

3390d ago

Major Versions

1.2.6 → 2.0.02017-02-17

### Community

Maintainers

![](https://www.gravatar.com/avatar/27d52216c92a2ba09006e9206a799e2ca1834e3180b16695dde99955aec76661?d=identicon)[legomolina](/maintainers/legomolina)

---

Top Contributors

[![legomolina](https://avatars.githubusercontent.com/u/9081996?v=4)](https://github.com/legomolina "legomolina (59 commits)")

---

Tags

phpormSimple

### Embed Badge

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

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

###  Alternatives

[matchory/elasticsearch

The missing elasticsearch ORM for Laravel!

3064.0k](/packages/matchory-elasticsearch)[simple-swoole/db

A db component for Simps.

216.8k3](/packages/simple-swoole-db)[modul-is/orm

Lightweight hybrid ORM/Explorer

1119.0k](/packages/modul-is-orm)[flightphp/active-record

Micro Active Record library in PHP, support chain calls, events, and relations.

164.0k11](/packages/flightphp-active-record)

PHPackages © 2026

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