Searching for a simple ORM

Hi folks.

I’m searching for an easy to use and simple ORM, matching the slimness patterns of Slim to create repositories, mappers and models of my tables from - or maybe generate them from an already existing DB schema as a plus. But without any annotations, non-PHP config files, DB migration support or even a DB modelling engine. Unfortunately most ORM are just overwhelming because they want to solve most or all DB-related narratives.

After a frustrated internet research I’ve asked the PHP folks in Reddit:
https://www.reddit.com/r/PHP/comments/1hmw6za/searching_for_a_simple_orm/

Their response can be summarized as “use Doctrine (or maybe another Doctrine alternative)”

What do you guys use when you want to handle 4-10 tables with some relations and still keep it simple without a large overhead? To be honest, I’ve already created my own simple ORM, but for a better security feeling I wish I could migrate to a maintained public accessible alternative. Or I’m the only dude afraid to make the last step into Doctrine?

Thanks in advance.

Doctrine is also what comes to my mind when you ask about a ORM, but for me, a QueryBuilder is much easier and more efficient when working with relational databases.

I worked with the notorm library years ago but I don’t know if it is still updated. For input validation I combined it with valitron, then you have a quite slim toolset for validation and database queries …

Thanks for your response. I just want to handle my tables as easy to use models to add OOP for data handling. It really looks like there is no “simple” ORM out there.

Somebody already created a Slim ORM. Unfortunately it is not maintained anymore and also not complete.
GitHub - danielefavi/slim-orm: Slim ORM is a lightweight PHP ORM with an API interface similar to the Laravel’s ORM (Eloquent).

Perhaps there really is a gap to be filled with a non-bloated, CRUD- and relation-only oriented ORM. Anyone interested in helping me create such a lib? I’ve already created a simple ORM, but it needs some love before it could be released or go public on GitHub.

What would you recommend as a simple query builder? Is it ok to create a Slim ORM based on DBAL or is there a better alternative?

The danielefavi/slim-orm package looks like a QueryBuilder and not like a ORM to me. The latest release was in 2022, so it might not be maintained anymore (like you said).

What would you recommend as a simple query builder?

I have had the best experience with the cakephp/database package. This is a very good and maintained / supported QueryBuilder from the CakePHP community.

I wrap that Connection class into a QueryFactory class. Example:

$query = $this->queryFactory->newSelect('users');

$query->select(['id', 'username']);
$select->where(['id' => 1]);

$rows = $query->execute()->fetchAll('assoc');

foreach ($rows as $row) {
    print_r($row);
}

Is it ok to create a Slim ORM based on DBAL or is there a better alternative?

I would not reinvent the wheel again in this case. You may also try other good query builders such as cycle/database, doctrine/dbal, laminas/laminas-db.

1 Like

Thank you!

But a query builder does not solve my needs to get a simple model layer into my application.

Right now, I have 4 classes to get a custom ORM for my needs (not finalized yet) plus some classes for a custom query builder. I only need to replace the query builder with a proper lib and I’m fine (except my custom ORM is not a well maintained lib).

It really looks like there is no simple and maintained ORM anymore. Idiorm was cool, but it is more dead than alive today.

the best I know and using for years
Idiorm

it has a very low learning curve

We use eloquent in a lib that we published for filtered crud (via lumen or laravel). We asked if the slim community is interested in a version for slim that uses eloquent and the feedback was negative. Url query language cruFd lib using Eloquent in Slim - #2 by tj_gumis

If you are more of the Active Records type there Eloquent( illuminate/database ) and of course Propel:

https://propelorm.org/

1 Like