tags:

views:

3935

answers:

15
+11  Q: 

Simple PHP ORM

I'm looking for an ORM (Object-Relational Mapper) for PHP. I want something simple that I can get started with quickly. I'm used to ActiveRecord in Rails, but I don't need a full framework. My partner knows PHP, but is not really a programmer, and learning a framework would take more time than the project.

Thanks, Craig

+12  A: 

You may want to try Doctrine. http://www.doctrine-project.org/

boxoft
I'd go this way, too. The Symfony camp is slowly moving away from Propel, and towards Doctrine.
Peter Bailey
simple is in my opinion something that hasn't any relation to doctrine...
Hippo
+1  A: 

Another option could be Propel.

hangy
A: 

I support @boxoft's recommendation of Doctrine.

However, in the spirit of options, I should mention the Zend_Db component of Zend Framework along with the Zend Framework ORM project.

leek
+1  A: 

It's not an ORM, but I use ADODB.

It is very simple to use, is rock-solid and very straight forward.

Toby Hede
If you decide upon ADOdb then install the C extension if possible. http://adodb.sourceforge.net/#download
leek
Dear god people, he made a valid suggestion that fit within the OP's parameters. Does ADODB suck? Maybe. Was it off topic or factually wrong? No. Don't down vote a guy because you disagree with his answer, down vote if the answer is factually incorrect or off topic.You sir get a +1 to round this suggestion back up to 0.
dcousineau
+1  A: 

I like Kohana so far, and it is simple to use by just extending a base class for each of your tables:

http://docs.kohanaphp.com/libraries/orm

Zak
+2  A: 

Check out Outlet ORM: http://www.outlet-orm.org/

Alvaro
Gotta second Outlet. Doctrine is comically bloated - it is WAY too big to be a sensible choice for anything but the lightest of server loads. Outlet does some clever stuff to stay out of your model's way and uses up about a tenth of the memory per request as Doctrine.
Shabbyrobe
A Doctrine blogger posted a response to this comment about Doctrine being "bloated". I've been using Doctrine for a while now and it works great. Having built in db migrations is also a useful feature.http://www.doctrine-project.org/blog/php-benchmarking-mythbusters
Chris Williams
"comically bloated"...
phidah
A: 

Kohana looks like what I'm looking for. I've not gotten a chance to use it yet -- I'm still using my hand-coded ORM. Thanks for the tip though!

booch
+1  A: 

I used Pear's DB_DataObject and it works pretty cool. It might not be very sophisticated but it's very simple and very lightweight.

lamelas
A: 

Good stand-alone ORMs i would suggest are (all have stable releases): - Doctrine (phpdoctrine.org) - Propel (propel.phpdb.org) - ezpdo (ezpdo.net)

you should not use: - Kohana -> as it is a full framework (including an orm) - ADODB -> as it is no ORM but a database abstraction layer - ZendDB/Zend ORM project -> ORM project is not stable and not officially maintained by zend

samsam
A: 

You might want to check out phpDataMapper. It's based on the DataMapper pattern instead of the ActiveRecord pattern as you had mentioned, but it is very lightweight and easy to use.

Vance Lucas
A: 

The most simple ORM layer for PHP i have seen is: SPOD

Hippo
+2  A: 

I've been working on a really simple nearly-zero-configuration single-class ORM called Idiorm.

It gives you a fluent query API that looks like this:

$widgets = ORM::for_table('widget')
    ->where('size', 'large')
    ->order_by_desc('name')
    ->find_many();

This will return an array of objects.

Another example: find a single object, update and save:

$widget = ORM::for_table('widget')->where('name', 'Basic Widget')->find_one();
$widget->name = 'Advanced Widget';
$widget->save();

This requires no model configuration (no model classes or XML files) - just database connection details. It's a nice drop-in replacement to clean up legacy code littered with raw SQL strings, and it's perfect for small, simple applications.

Have a look at the documentation on Github. Also, see this blog post about Idiorm. Any feedback greatly appreciated.

UPDATE: I have recently released another project - Paris - which is a very lightweight Active Record implementation built on top of Idiorm.

j4mie
Very nice! I like this one a lot. +1
Bryan
Thanks, It's really good for small app.
yogs
A: 

Repose PHP ORM is another potential solution.

Beau Simensen
+3  A: 

Try DaBase - most easy to use and lightweight ORM for PHP!

SeniorDev
A: 

Check out Simple ORM for PHP it is intended to be a very light weight version of Hibernate and requires far fewer steps to setup. Development is still in progress and help is needed.