[Dcphp-dev] Feedback on ORMs

Hans Lellelid hans at velum.net
Mon Jun 11 22:36:37 EDT 2007


Howdy,

> The article was related to the whole Java/Ted Husted revolution;  namely
> the IOC pattern that was preached and launched the Spring and Hibernate
> combo right up until Java attempted to quell the Java masses through EJB
> 3.  I believe the developer was trying to sell a book he wrote on EJB 3
> and basically stated something to the effect that object relational
> mapping tools are useless and that every developer should stop dancing
> around SQL and just use it.  He also seemed to think that it perpetuated
> a lack of knowledge in SQL and made maintenance more difficult.
> 
> While I agree that all developers using databases are better off knowing
> SQL, I can't help but feel like its a reactionary response that is
> probably self-motivated; but a little surveying should clear things up.  

I wholeheartedly agree.  While the whole Ted Husted ORM=Vietnam movement
makes some very good points about the differences between the object and
relational representation of the world, I think that from a  practical
perspective ORM solutions present a really workable solution for most
database-driven applications.  I feel very safe in saying that the
databases that drive most of the PHP apps out there aren't very complex
-- and neither are the queries executing against those databases.  On
one hand there are some obvious performance reasons why PHP doesn't pair
well with intensive database work  and I'd surmise that PHP's historic
pairing w/ MySQL has helped keep databases (and the SQL people use to
interact with them) really rudimentary.

Point is, though, that most of the apps I write tend to do a lot of the
same or very similar stuff.  I have PHP code snippets that will need to
fetch rows from a database, update rows in a database, insert rows, etc.
 I think ORM solutions fit perfectly into this model.

> It seems to me that ORMs facilitate protecting against sql injection,
> add in transaction control, help create objects quickly and make objects
> that are predictable and thus are quantifiable.  Many even offer
> meta-data.  I have used doctrine and propel (PHP based ORMs) and was
> satisfied with the results.  Furthermore, I noticed that Yahoo started
> using symfony for their bookmarks project, which uses ORMs by default
> (but the project appears experimental).

Yes, I think that the security benefits and maintenance benefits with
ORM layers are huge.  I would add to the list that ORM layers can also
fit neatly into a unit test framework.

I've certainly known a number of larger-scale-production projects out
there using what I'd consider "heavy" frameworks w/ ORM layers.  After
recently deploying a site using Prado + ORM (Propel), I am very
comfortable saying that any framework weight can quickly be overcomed
through bytecode compiling and caching.  And honestly, at my company we
build intranet/extranet collaboration tools using a Symfony-like
framework (w/ ORM) without any bytecode pre-compiling or caching and
have never had any performance issues.

> So I wanted to stimulate a little discussion on the matter.  What is
> your take on ORMs?  Have you ever used them on a large scale production
> server? Any horror stories? Any pleasant surprises?  If you like them,
> which ones do you use?  Do you feel like it makes the maintenance phase
> easier?

Obviously you know that I use Propel ;)  I have used Hibernate in Java
and like it quite a bit.  I have played briefly with ActiveRecord
patterns, but have never actually built an app around that model.  I'd
like to get to know Doctrine better; everyone I've talked to has been
very impressed with that project.

I'm definitely interested to learn what others from the group are doing
w/ ORM in PHP.  When I started building Propel some 4 years ago (?!),
there was basically no interest in ORM in the PHP world.  PHP has come
along way since then.  I think the PHP5 object model had a lot to do
with giving rise to these OO frameworks -- though maybe it was just the
demand for these big OO frameworks that was giving rise to the improved
OO stuff in PHP5.  Chicken & egg, I guess.

Anyway, good discussion topic.

Hans


More information about the Dcphp-dev mailing list