Archive for March, 2013

Doctrine ORM for PHP

No Comments »

Doctrine is a set of PHP libraries primarily focused on providing persistence services and related functionality. Object relational mapper (ORM) for PHP that sits on top of a powerful database abstraction layer (DBAL).

One of Doctrine’s key features is the option to write database queries in a proprietary object oriented SQL dialect called Doctrine Query Language (DQL), inspired by Hibernates HQL.

This provides developers with a powerful alternative to SQL that maintains flexibility without requiring unnecessary code duplication

Usage demonstration

Entities in Doctrine 2 are lightweight PHP Objects that contain persistable properties. A persistable property is an instance variable of the entity that is saved into and retrieved from the database by Doctrine’s data mapping capabilities via the Entity Manager:

$user = new User();
$user->name = "Name";
$user->password = "Password";
$entityManager->persist($user);
$entityManager->flush();
echo "The user with id $user->id has been saved.";