If you have ever pulled your hair out over maintaining SQL statements intermingled with your PHP project code you might not be alone. Perhaps you considered abstraction or wished your database had an API. You might have even heard of an Object Relational Mapper (ORM).

Let’s take a quick look at ORM for your next PHP project.

The Perfect (st)ORM

The ORM offerings for PHP projects have come a long way. A query on stackoverflow returns over 100 hits on php+orm. With that in mind, focusing on one PHP ORM might be helpful as you to consider your next PHP project.

As with any solution in the PHP community you can expect to see several contenders for the best mousetrap prize. While no ORM is perfect, each will cater to specific needs and have varied levels of integration or consideration for PHP frameworks. Features can range from simplified abstraction to code generation to support for various underlying databases such as MySQL, PostgreSQL, SQLite, Firebird to IBM DB2, Microsoft SQL Server, and Oracle.

Doctrine was mentioned recently in the RWH review of zfKit as part of its easy out-of-the-box Zend Framework experience. You may also find features in the Doctrine 2.0 release to be of interest if you need caching or support for writing your own interfaces and abstract classes for when your database of choice is not supported at the time of a stable release.

A recent presentation highlighted Doctrine 2.0 as being a fresh take on the expansion of the PHP ORM options showing up in sourceforge, github, and related project hosting services.

Doctrine 2 – Not The Same Old Php Orm

View more



Jonathan Wage


(Slide 14 is an instant favorite)

I want a $drug->new()

Of course, even if you focus on Doctrine you find references to alternative ORM options such as Propel. This is because an ORM can often be found intermingled in wider discussion of PHP MVC frameworks.

For example, Propel is often mentioned in relation to Symfony and CodeIgniter or as another alternative to using Doctrine with other PHP MVC frameworks. In addition, the Propel blog is a good resource for extracting the value when using Propel or any ORM in general.

Again, there is more than just one ORM option in the PHP community. You may have even ended up writing your own at one point or found your MVC framework came with a library that supplied ORM functionality.

When selecting an ORM, what are your considerations? What did you expect to gain from the ORM? Have you had success or strugles with use of an ORM in your projects?

Let us know in the comments below!