explaingit

doctrine/orm

10,176PHPAudience · developerComplexity · 3/5Setup · moderate

TLDR

Doctrine ORM is a PHP library that maps database tables to PHP objects so you can read and save data without writing raw SQL, widely used in Symfony projects, with version 3.0 currently in development.

Mindmap

mindmap
  root((Doctrine ORM))
    What it does
      Map PHP objects to DB
      Transparent persistence
      DQL query language
    Architecture
      Sits on top of DBAL
      Database-agnostic
    Use Cases
      Symfony web apps
      PHP backends
      Relational data
    Versions
      Stable 2.7 and 2.8
      Upcoming 3.0
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Define your application data as PHP classes and let Doctrine automatically read and write them to a MySQL or PostgreSQL database.

USE CASE 2

Write complex database queries using Doctrine's DQL language instead of raw SQL, working with objects and relationships instead of table rows.

USE CASE 3

Build a Symfony-based web application that needs to store, retrieve, and relate structured data in a relational database.

USE CASE 4

Migrate a PHP project from raw SQL queries to an ORM to reduce repetitive boilerplate and centralize data access logic.

Tech stack

PHPSQLDQL

Getting it running

Difficulty · moderate Time to first run · 1h+

Requires an existing PHP project with Composer and a relational database such as MySQL or PostgreSQL.

In plain English

Doctrine ORM is a library for PHP applications that handles the connection between code objects and a relational database. It is called an object-relational mapper because it maps the data stored in database tables onto PHP objects, letting developers work with data as normal objects in code instead of writing raw SQL queries. The core idea is that a developer defines their data structures as PHP classes, and Doctrine handles reading those objects from the database and writing them back when changes are made. This is called transparent persistence: the developer works with regular PHP objects, and the library takes care of synchronizing them with the database behind the scenes. For cases where developers need more control over database queries, Doctrine provides its own query language called DQL (Doctrine Query Language). DQL looks similar to SQL but operates on objects and their relationships rather than on raw table rows and columns. This makes complex queries easier to write when your data model is organized around objects. Doctrine ORM sits on top of a separate database abstraction layer called DBAL, which handles the actual communication with the database engine. This separation means the ORM itself does not need to know the details of which database is being used. The repository shown here is for the upcoming Doctrine 3.0, which contains significant changes from earlier versions. The stable releases at the time of the README were the 2.7 and 2.8 branches. Doctrine ORM is a widely used library in the PHP ecosystem, particularly in projects built with the Symfony framework, though it works independently as well.

Copy-paste prompts

Prompt 1
Show me how to define a User entity class in Doctrine ORM with id, email, and name fields and map it to a database table using annotations.
Prompt 2
I need to find all orders placed in the last 7 days using Doctrine ORM. Write the DQL query and the PHP repository method to execute it.
Prompt 3
How do I set up a one-to-many relationship between a User entity and a Post entity in Doctrine ORM, and how do I query a user's posts?
Prompt 4
What are the main breaking changes between Doctrine ORM 2.x and the upcoming 3.0, and what would I need to update in my project to migrate?
Open on GitHub → Explain another repo

← doctrine on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.