PHPackages                             twodudes/simpleorm - 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. twodudes/simpleorm

ActivePhp-library

twodudes/simpleorm
==================

Simple php orm.

05PHP

Since Jan 24Pushed 9y ago2 watchersCompare

[ Source](https://github.com/two-dudes/Simpleorm)[ Packagist](https://packagist.org/packages/twodudes/simpleorm)[ RSS](/packages/twodudes-simpleorm/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Simpleorm
=========

[](#simpleorm)

Super simple ORM on top of PDO. Based on the data mapper pattern.

### Installation

[](#installation)

Installation with composer:

```
composer require twodudes/simpleorm
```

### Quickstart

[](#quickstart)

##### The model

[](#the-model)

```
use Simpleorm\Mapper\Pdo\PdoMapper;

/**
 * @property int    $id
 * @property string $name {"default": "John"}
 *
 * @method static PdoMapper getMapper() {"table": "test"}
 */
class User extends AbstractModel
{

}
```

Fields are defined as doc properties, because this is

- convenient
- easily recognizeable by the IDE
- you dont have the unnecessary boilerplate code with getters and setters

##### The mapper

[](#the-mapper)

The mapper once again is defined in the doc comments section. Here we specify, that our user will be handled with the PdoMysqlMapper

```
@method static PdoMapper getMapper() {"table": "test"}
```

To get the mapper, simply use

```
User::getMapper();
```

We use a mix of active record and data mapper aproach to managing your entities, therefore you can use it like this:

```
$user = User::getMapper()->fetch(1);
$user->name = 'NewName';
$user->save();
```

If you want your custom logic and methods, just extend the desired mapper and you are good to go:

```
class UserMapper extends PdoMysqlMapper
{
    public function fetchComplicatedReport($someParams)
    {
        $stmt = $this->getConnection()->prepare('...');
        $stmt->execute();

        return $stmt->fetchAll();
    }
}
```

Use this mapper in your model

```
/**
 * @property int    $id
 *
 * @method static UserMapper getMapper() {"table": "test"}
 */
class User extends AbstractModel
{
}
```

And in your service/controller:

```
$report = User::getMapper()->fetchComplicatedReport();
```

##### The collection

[](#the-collection)

By default the fetchAll mapper method will return a collection. It is more convenient to work with, than just plain array, and has a lot of usefull methods.

```
$users = User::getMapper()->fetchAll(['country' => 'Cyprus']);
```

For more details, check the code

##### What else?

[](#what-else)

###### Writing own mappers

[](#writing-own-mappers)

You can write your own mapper for any storage you want. Just implement the MapperInterface

###### MysqlPdo mapper connection settings

[](#mysqlpdo-mapper-connection-settings)

```
PdoMysqlMapper::setConnectionConfig(array(
    'user' => 'user',
    'password' => 'password',
    'host' => '127.0.0.1',
    'port' => '3306',
    'db'   => 'simpleorm_test'
));
```

###### Getters and setters

[](#getters-and-setters)

If you need setters and getters - you can define them explicitly, they will be used before the magic \_\_get \_\_set.

###### Mapper decorators

[](#mapper-decorators)

You can add decorators to mappers, for caching purposes, for example

###### Model state

[](#model-state)

Models can be clean (unchanged, when fetched from the storage) and dirty (something is changed). You can always access the models cleanData and data, to see what changed.

##### Final word

[](#final-word)

As you see, it's super simple, yet effective. If you need an ORM, but dont want to mess with giants like Doctrine, i hope Simpleorm will server you for good.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8eb68ea0a238b346910752a25d7ed2ba13d13636a5eeffa8b7f817164d73cbe5?d=identicon)[megawilddaddy](/maintainers/megawilddaddy)

---

Top Contributors

[![megawilddaddy](https://avatars.githubusercontent.com/u/1647204?v=4)](https://github.com/megawilddaddy "megawilddaddy (27 commits)")

### Embed Badge

![Health badge](/badges/twodudes-simpleorm/health.svg)

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

PHPackages © 2026

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