What is ORM?

ORM (Object-relational mapping), also known as O/RM, and O/R mapping is a programming approach for converting data between incompatible type systems.

Many full stack frameworks provide their own database abstraction approaches or ORMs.

Standalone database abstraction layers and ORMs to check out:

  • Aura SQL - Extension to the native PDO along with a profiler and connection locator.
  • DataMonkey - Database ORM for PHP build on top of Doctrine.
  • Doctrine - Home to several PHP libraries primarily focused on database storage and object mapping. The core projects are a Object Relational Mapper (ORM) and the Database Abstraction Layer (DBAL) it is built upon.
  • Eloquent - Illuminate Database component, used in Laravel framework but also a standalone component.
  • Medoo - Light PHP database framework to accelerate development.
  • Propel - A highly customizable and blazing fast ORM library.
  • ProxyManager - Library that aims at providing abstraction for generating various kinds of proxy classes.
  • RedBeanPHP - Easy to use ORM for PHP.
  • safemysql - A real safe and convenient way to handle MySQL queries.
  • Spot ORM - simple and efficient DataMapper built on Doctrine Database Abstraction Layer.
  • Zend\Db - Zend Database Component.

Design patterns

There are mainly two main design patterns used in ORMs - Active Record and Data Mapper.

When not to use ORM?

As some articles have pointed out (1, 2, 3), ORM is anti-pattern that violates principles of object-oriented programming.

As an alternative to ORM, there is Pomm. It does not propose an abstraction layer and is dedicated to Postgres making developpers able to code directly in SQL to fetch entities. It matches object/relational impedance by using the projection relational operation in order to hydrate flexible instances. It is particulariry suited to build in-house transactional or reporting applications.

See also

Here are some other useful and updated resources to read or check as well: