Doctrine: object-relational mapping for PHP



Doctrine is a powerful object-relational mapper for PHP. David Brewer introduces the library and demonstrates how it can save you time and effort as you develop database-driven websites.


Doctrine is an object-relational mapper for PHP 5. Over the past three years it has grown from a promising one-developer project to a 1.0 release as an officially supported ORM for the popular symfony framework.

I’ve been using Doctrine on symfony-based web projects for two years now. In this session, I’ll give a high level tour of the library, focusing on the features that will save you time in your day-to-day development. The session will assume some familiarity with object-oriented programming in PHP5, but will be light on code.

Some of the features you can expect to learn about include:

  • Use the Doctrine Query Language (DQL) to write queries using the language of your model rather than your relational database. Get back hydrated objects.
  • Start from a yaml-based schema file and automatically create your database. Or, start from an existing database and automatically create your schema file. Either way, your model classes are generated for you.
  • Hydrate objects with all their related objects pre-loaded… or, lazy-load the relationships only when they are requested.
  • Use a sophisticated selection of hooks and event listeners to inject custom functionality into your model at various levels: system-wide, for one connection, or per model class.
  • ‘Behaviors’ add common types of functionality to a record class. Choose from a variety of useful included behaviors such as ‘Timestampable’ or ‘Searchable’, or implement your own functionality shared by several classes in your model.

Speaking experience