maggienelson.com | more blog archives

ORM in the PHP World

2009-05-21

Yesterday I gave a talk at the php|tek 2009 Conference about the ORM in the PHP World. In the first part of the presentation, I'm focusing on what an ORM is, what would make a great ORM, design patters for ORM and tying ORM systems to the PHP world in terms of philosophy, uses and approaches. The second part of the presentation talks about a list of ORMs that I have seen and their pros and cons.

The ORMs I mention:

I plan on talking about each of these ORMs in detail in separate blog posts, so stay tuned!

Comments (18)

2009-05-24 08:22:56 Lewis Zhang said:

Lewis from the CoughPHP team here. It's nice to see more interest in orm's for php. You mention in your slides that CoughPHP is "very light, very simple" which is absolutely true—and we have worked very hard to keep it that way! But don't forget to check out some of our more advanced features like collections and code generation. Drop me a line if I can be of any use to your writing.

2009-05-25 08:44:36 Kestas said:

Just what I was looking for. Brief overview of php orms :) Thanks!

2009-05-26 10:04:24 maggie said:

Joshua - I mentioned Symfony in the presentation specifically for this purpose: it uses an ORM as a plug-in instead of being one, which I thought was kind of unique among the available frameworks and worth mentioning. Thanks for pointing it out, too!

2009-05-26 10:09:13 maggie said:

Bill - I also prefer writing SQL whenever possible (it's not really that difficult!) I tried to talk about the idea in the PHP world that anything that has to do with the database is the ORM (much like I sometimes get called a DBA even if I just write some SQL). Classes that generate SQL are sometimes considered an ORM because, hey, there's objects AND tables in one class! It must be ORM! :) This definitely isn't the case, and I wanted to illustrate this by using a concrete example. I've very glad there seems to be a lot of interest about ORMs in PHP - I am very curious to see what the PHP community will come up with over time to solve this problem. (Maybe we'll do away with relational databases altogether? *gasp*)

2009-05-30 11:04:35 Bill Karwin said:

"...anything that has to do with the database is the ORM..." That's just not accurate, and saying it -- even informally -- only makes developers more confused than they already are about database programming.

2009-06-03 13:30:54 Philip Graham said:

As a propel user I'd like to point out that it no longer uses Creole. It now uses PDO for it's database access.

2009-06-04 04:41:47 Trophaeum said:

I am a propel dev so I am biased but we rarely use Creole anymore, we rely extremely heavily on PDO since 1.3 was released, seems it really got glossed over considering the amount you looked at, the Criteria example shown isn't valid either. Not that I mind, it's some publicity for Propel which people seem to be ignoring even when its a good solution but I dislike having incorrect information spread about it.

2009-06-06 15:17:59 Mark said:

Can you post some more examples of Domain Objects with Data Mappers done in PHP. In your slides you said that this was your favorite technique. Thanks

2009-05-22 04:18:32 Joshua May said:

Just a note, too, symfony isn't an ORM - it just uses third party ORMs (Propel, Doctrine, etc)

2009-05-22 02:13:52 Sergey said:

And this... interesting: http://phplightorm.wiki.sourceforge.net/LightOrm+vs+Propel+vs+Doctrine+benchmark

2009-05-22 01:57:42 Sergey said:

There is one more ORM for PHP: LightOrm http://sourceforge.net/projects/phplightorm Thanks :)

2009-05-21 16:11:34 Bill Karwin said:

Great job on the presentation. Wish I could have been there. One comment: Zend_Db_Select isn't part of an ORM layer (it's not even worth calling it object-oriented). It's a class to help you build SELECT queries -- procedurally. Your example showing how an extensive use fo Zend_Db_Select is less readable than a literal SQL query. This misses the point. I never suggested using Zend_Db_Select when you can more easily just write out the complete SELECT query. Instead, Zend_Db_Select is the alternative to writing meticulous and error-prone code when you're building up a SELECT query dynamically, using complicated application logic. You know, adding SQL clauses and conditions a bit at a time by concatenating strings together. I do recommend writing literal SQL when possible, and I wrote this recommendation in the docs for Zend_Db_Select.

2009-05-21 15:02:07 Jacques Fuentes said:

I'm sure this was a great presentation. I wish I could have been there! If you are going to take some time to write more about ORMs for PHP, I'd like for you to consider speaking about a new ActiveRecord implementation that was just released a few days ago as beta. It is very much like the ActiveRecord used by Ruby on Rails. It requires PHP 5.3 as it makes use of the latest and greatest features: namespaces, late-static binding, and closures. The code is hosted on launchpad. We have some detailed examples on our blog found here: http://www.derivante.com/2009/05/19/php-activerecord-available-for-beta-testing/ Please take a look. Thanks.

2009-05-21 13:25:49 maggie said:

Hey Lukas - can you provide some good examples to illustrate this? I've tried to not be too partial in this presentation (it's pretty difficult, there seems to be a lot of philosophy behind the choices people make when ORMs are concerned). I like the idea of having SQL-like languages, so I'd be curious to see some good examples (not just the few I found online).

2009-05-21 13:29:25 Will Bond said:

I'm very interested to read your blogs on all of these different ORMs. I've checked out quite a number of the big ones, but you've got quite a few here I've never heard of before such as Xyster, dOrm, PHPLing, Outlet and ORMer. I threw my hat into the PHP ORM ring back in late 2008 with Flourish (http://flourishlib.com). It is a modular general-purpose PHP5 library, but the ORM is definitely one of the more advanced parts. I'm interested to see how it compares to some of these other ORMs.

2009-05-21 13:22:18 Lukas said:

I must admit I am partial to Doctrine and thats the PHP ORM I know best, which is why I didn't understand the point of your complex Doctrine example? To me the two most important aspects of Doctrine is that I can write my queries as one string in DQL and more importantly, that the DQL is not only aware of the relations of the various objects, but that I can actually inject logic into DQL from my model. I am not sure if this is offered in any other PHP ORM.

2009-05-21 12:52:30 jwage said:

Btw. Nice presentation on orms. It covers the spectrum thoroughly :)

2009-05-21 12:51:54 jwage said:

In your slides I saw this code example: DQL complicated example static function sort2dBySubLength($arr, $key, $order){ foreach($arr as $sub) $sc[] = count($sub[$key]); $order = $order == 'desc' ? SORT_DESC : SORT_ASC; array_multisort($sc, SORT_NUMERIC, $order, $arr); return $arr; } I am trying to understand what it is for? It says it is a DQL example?