Maggie Nelson

ORM in the PHP World

by maggie on May.21, 2009, under entry

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!

:, , , ,
20 comments for this entry:
  1. jwage

    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

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

  3. Lukas

    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

    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

    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

    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

    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

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

  9. Sergey

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

    Thanks :)

  10. Joshua May

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

  11. Lewis Zhang

    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.

  12. Kestas

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

  13. maggie

    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!

  14. maggie

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

  15. Bill Karwin

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

  16. Philip Graham

    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.

  17. Trophaeum

    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.

  18. Mark

    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

  19. ORM в мире PHP | Блог веб-разработчика

    [...] 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: Описание на [...]

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Tags

RSS Planet PHP

  • Module Bootstraps in Zend Framework: Do's and Don'ts
    I see a number of questions regularly about module bootstraps in Zend Framework, and decided it was time to write a post about them finally. In Zend Framework 1.8.0, we added Zend_Application, which is intended to (a) formalize the bootstrapping process, and (b) make it re-usable. One aspect of it was to allow bootstrapping of individ […]
    Matthew Weier O'Phinney
  • Webinar - New in Zend Framework 1.10!
    Zend Framework 1.10 sports a ton of new features, as well as completely revamped online documentation. In this webinar, Matthew Weier O’Phinney, Framework Project Lead, and Ralph Schindler, Zend Framework Software Engineer, will present a synopsis of the new features, discuss the new online documentation system and how it’s built, and answer your questions a […]
    Zend Developer Zone
  • ConFoo PHP 5.3 == Awesome! Slides
    Finally managed to upload my slides from my ConFoo PHP 5.3 == Awesome! talk. Slides Thanks for all the attendees, especially those who asked questions […]
    Ilia Alshanetsky
  • ConFoo PHP 5.3 == Awesome! Slides
    Finally managed to upload my slides from my ConFoo PHP 5.3 == Awesome! talk. Slides Thanks for all the attendees, especially those who asked questions […]
    Ilia Alshanetsky
  • Slides from my Confoo.ca talk now online
    I’ve just uploaded the slides from my confoo.ca talk “Making software management tools work for you”. You can download the slides from here. Thanks again to everyone who attended! Please give me feedback on joind.in. […]
    John Mertic