OEIC

Object Relational Mappers

I’ve always been a bit skeptical about Object Relational Mapping (ORM) tools in PHP. Why provide an object wrapper around a database if you have to know all the details of your database schema to start with? Isn’t the point of objects to hide complexity? To my eyes, using an ORM to save a 1:* parent-children record set is just as complex as doing it via SQL; there’s just a different programming interface. Ted Neward has written a popular essay comparing ORM development to Vietnam: essentially, too much work for not enough return.

I feel like ORMs in PHP have it backwards. Rather than reading a database schema to generate PHP objects for access/updating a database, ORM tools should use reflection to examine PHP objects and create a corresponding database schema and PHP methods to use it. That would result in much simpler code.

However, due to a thread on the DC PHP mailing list the other day, I’ve changed my opinion a bit. While using ORMs is just as complex as using native SQL (ranging from very simple to Hmmm…), ORMs provide enough utility methods (escaping, SQL syntax builders, etc.) that I’m considering using them for future projects just to ease the trouble of building dynamic WHERE clauses.

Propel seems like a very mature release, and its docs are quite good as well. I’ve also heard good things about Doctrine. Zend Framework offers Zend_Db, which I’m currently using.

No comments     Jump to comment form | comments rss | trackback uri

Say what?

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>





About this entry

Categories