OR Mapping PHP

From Noah.org
Revision as of 14:26, 4 August 2007 by Root (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search


Object-Relational mappers can quickly go from time-saving to complex nightmare. I have experience with Hibernate and while it is impressive and sophisticated you have to be very disciplined and willing to chain yourself to Hibernate. The learning curve is steep and maintainance is not trivial. It's the maintainance that bugs me. What's the point of an OR mapper if it does not make your life easier? Also, Hibernate is not a totally transparant system. It hides many database details, but in trade, you have to concern yourself with Hibernate issues. A developer new to a project cannot utilize Hibernate generated classes without having a good understanding of Hibernate. I'm not saying I wouldn't consider Hiberante out of hand, but I wish there were some middle ground for Java.

The Vietnam of Computer Science O/R Mapping is a quagmire

Unfortunately, PHP does not have many good OR Mapping solutions. Luckily the two that I know about are pretty simple and flat.

DB_DataObject is a free, flat OR mapper available through PEAR. It's pretty simple and appears easy to use; although, I have not tried it. It appears to generate instances dynamically, so I wonder if that hurts performance. You can manually edit table mapping files, or somehow, encode these maps in subclasses.

dbag is my own free, OR mapper. It's marginally more fussy than DB_DataObjects because it is a static PHP code generator. It's written in Python, which might seem like an odd choice to PHP people. One "advantage" is that once you generate classes you do not need the code generator again unless you want to update classes to reflect schema changes.