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

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

richbuilds/orm
==============

A wireless ORM for PHP

17[1 issues](https://github.com/richardathome/Orm/issues)PHP

Since Jul 19Pushed 3y ago1 watchersCompare

[ Source](https://github.com/richardathome/Orm)[ Packagist](https://packagist.org/packages/richbuilds/orm)[ RSS](/packages/richbuilds-orm/feed)WikiDiscussions develop Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![RichBuilds Components](/docs/richbuilds_logo.png)](https://richbuilds.com)

🔗 ORM
=====

[](#-orm)

A wireless, typesafe ORM for PHP 8.1.

Currently only MySql data sources are supported, but Sqlite and Postgres are planned.

The ORM takes all it's instruction from the database. Make sure your primary and foreign keys are set up correctly.

Example usage:
--------------

[](#example-usage)

```
$orm = new Orm(new PDO('dsn','username','password'));
```

Model
=====

[](#model)

- represent a row in a table

Create an empty model
---------------------

[](#create-an-empty-model)

- fails if table doesn't exist

```
$post = $orm->Model('posts');
```

Set a column value
------------------

[](#set-a-column-value)

- fails if column doesn't exit
- fails if value is not a compatible datatype for the column

```
$post->set('title', 'My Post Title');
```

Set multiple column values
--------------------------

[](#set-multiple-column-values)

- no columns are changed if any fail

```
$post->set([
    'title'='My Post Title',
    'body'=>'My post body.',
    'created'=>new Datetime()
]);
```

Set a foreign key column to an existing record
----------------------------------------------

[](#set-a-foreign-key-column-to-an-existing-record)

- fails if the parent record doesn't exist

```
$post->set('author_id', 1);
```

Set a foreign key column to a new Model
---------------------------------------

[](#set-a-foreign-key-column-to-a-new-model)

- fails if Model is not of correct type

```
$user = $orm->Model('user');
$post->set('author_id', $user);
```

Set a foreign key column to n array of parent model values
----------------------------------------------------------

[](#set-a-foreign-key-column-to-n-array-of-parent-model-values)

```
$user = ['name'=>'foo','password'=>'password'];
$post->set('author_id', $user);
```

Set the children of a model
===========================

[](#set-the-children-of-a-model)

- accepts arrays of fields or models

```
$user->set('comments',[
    ['comment'=>'foo', 'visible'=>false],
    $orm->Model('comments')->set('comment', 'bar')
]);
```

Save the model, it's parents and it's children
==============================================

[](#save-the-model-its-parents-and-its-children)

- inside transaction, rolls back on error
- all keys are updated

```
$post->save();
echo $post->getPk();
```

Fetch a parent model
====================

[](#fetch-a-parent-model)

- fails if column name is not a foreign key or parent doesn't exist

```
$author = $post->fetchParent('author_id');
// SELECT * FROM users WHERE users.id = posts.author_id
echo $author->get('name');
```

Fetch children lazily
=====================

[](#fetch-children-lazily)

- fails if child table name is not a child of the parent

```
$posts = $user->fetchChildrent('posts');
// SELECT * FROM posts WHERE posts.author_id = user.id
```

Query
=====

[](#query)

Create a query
--------------

[](#create-a-query)

```
$posts = $orm->Query('posts',
    [
        'author_id'=>1
    ],
    [
        'per_page'=>10
    ]
)

// SELECT * FROM database.posts WHERE database.posts.author_id = :1 LIMIT 10 OFFSET 0;

foreach($posts as $post) {
  echo $post->get('title');
  $comments = $post->fetchChildren('comments');
}
```

###  Health Score

9

—

LowBetter than 0% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity22

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/14c260005a69b17ccb71e8a10be15f34aea6c26c12611bc7c91ff940bed4ce15?d=identicon)[richbuilds](/maintainers/richbuilds)

---

Top Contributors

[![richardathome](https://avatars.githubusercontent.com/u/40023?v=4)](https://github.com/richardathome "richardathome (36 commits)")

---

Tags

databasedbalorm

### Embed Badge

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

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.8k117.8M121](/packages/jdorn-sql-formatter)[backup-manager/backup-manager

A framework agnostic database backup manager with user-definable procedures and support for S3, Dropbox, FTP, SFTP, and more with drivers for popular frameworks.

1.7k1.6M11](/packages/backup-manager-backup-manager)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M88](/packages/propel-propel1)[insolita/yii2-migration-generator

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

108508.0k5](/packages/insolita-yii2-migration-generator)[xpdo/xpdo

A PDO-based Object/Relational Bridge Library

7088.4k4](/packages/xpdo-xpdo)[voku/session2db

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

2920.0k](/packages/voku-session2db)

PHPackages © 2026

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