ORM and Active Record Pattern in PHP?


Question

There are two things that seem to be popular nowadays and I was wondering what are the pros and cons of using something like this: http://codeigniter.com/user_guide/database/active_record.html ?

Another thing is ORM (Doctrine for instance). What are the benefits of using these?

1
14
11/22/2015 8:22:20 PM

Accepted Answer

ActiveRecord is a pattern common in ORMs. Doctrine is an ORM which uses an ActiveRecord'ish style.

Some benefits of using tools like Doctrine:

  • Database independence: The code should be easy to port to different DBs. For example, I often test using SQLite and use MySQL or Postgre in production with no changes in code.
  • They reduce the amount of code you have to write: A large part of application code deals with communicating with the database. An ORM takes care of most of that, so you can concentrate on writing the actual app.

Of course, they don't come without disadvantages:

  • Doctrine is heavy so it is slower than using straight SQL
  • ORMs can be complex, adding some weight to what you have to learn, and they can sometimes be difficult to understand for inexperienced programmers
19
7/11/2009 1:44:50 PM

You can take a look at these questions though they're not exactly PHP specific:


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon