Maggie Nelson

databases and code goodness

  • Author: maggie
  • Published: May 21st, 2009
  • Category: entry
  • Comments: 20

ORM in the PHP World

Tags: , , , ,

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!

Tags: , , , ,

20 Responses to “ORM in the PHP World”


  1. jwage
    on May 21st, 2009
    @ 12:51 pm

    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?


  2. jwage
    on May 21st, 2009
    @ 12:52 pm

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


  3. Lukas
    on May 21st, 2009
    @ 1:22 pm

    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.


  4. maggie
    on May 21st, 2009
    @ 1:25 pm

    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).


  5. Will Bond
    on May 21st, 2009
    @ 1:29 pm

    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.


  6. Jacques Fuentes
    on May 21st, 2009
    @ 3:02 pm

    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.


  7. Bill Karwin
    on May 21st, 2009
    @ 4:11 pm

    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.


  8. ORM in the PHP World - Maggie Nelson
    on May 21st, 2009
    @ 11:25 pm

    [...] the rest here: ORM in the PHP World – Maggie Nelson Share and [...]


  9. Sergey
    on May 22nd, 2009
    @ 1:57 am

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

    Thanks :)


  10. Sergey
    on May 22nd, 2009
    @ 2:13 am

    And this… interesting:

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


  11. Joshua May
    on May 22nd, 2009
    @ 4:18 am

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


  12. Lewis Zhang
    on May 24th, 2009
    @ 8:22 am

    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.


  13. Kestas
    on May 25th, 2009
    @ 8:44 am

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


  14. maggie
    on May 26th, 2009
    @ 10:04 am

    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!


  15. maggie
    on May 26th, 2009
    @ 10:09 am

    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*)


  16. Bill Karwin
    on May 30th, 2009
    @ 11:04 am

    “…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.


  17. Philip Graham
    on Jun 3rd, 2009
    @ 1:30 pm

    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.


  18. Trophaeum
    on Jun 4th, 2009
    @ 4:41 am

    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.


  19. Mark
    on Jun 6th, 2009
    @ 3:17 pm

    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


  20. ORM в мире PHP | Блог веб-разработчика
    on Oct 22nd, 2009
    @ 4:41 am

    [...] Comprehensive list of the object relational mapping tools and frameworks. part one: php • ORM in the PHP World • ORM in PHP • PHP ActiveRecord with PHP 5.3 • LightOrm: Описание на [...]

© 2010 Maggie Nelson. All Rights Reserved.

This blog is powered by the Wordpress platform and beach rentals.