Doctrine (PHP)

from Wikipedia, the free encyclopedia
Doctrine
Basic data

Publishing year April 13, 2006
Current  version 2.6
(December 21, 2017)
operating system Platform independence
programming language PHP
category Framework , object relational mapper
License MIT license
www.doctrine-project.org

The Doctrine Project or shortly Doctrine is a framework that the possibility of object-relational mapping ( English object-relational mapping , ORM ) and a database abstraction layer ( english database abstraction layer ) for PHP provides version 5.3. This enables easier access to different database types (e.g. MySQL or Microsoft SQL Server ) than would be possible with pure PHP. Doctrine is based on Hibernate , a similar project for Java .

Database queries can be formulated in Doctrine's own intermediate language, Doctrine Query Language (DQL). The object-oriented approach enables abstract work regardless of the database used. Database contents can also be managed in an object-oriented manner without providing a wrapper for it. The object-relational functionality is assigned to the objects themselves without the need for complex programming in PHP.

Since the DBAL can address several database servers, DQL only includes the amount of SQL functionality that is available in all SQL systems supported by Doctrine. This means that more complex joins , for example, are not always possible. Doctrine also has strict restrictions on the structure of the databases. So z. B. each table must have a primary key . This can lead to problems, especially with large existing databases that were previously maintained with regular SQL.

Application example

As an example, if a new user object is to be created in the database, it could look like this written in PHP:

 $user = new User();
 $user->setName("Max");
 $user->setPassword("test");
 $entityManager->persist($user);
 $entityManager->flush();
 echo "Der Benutzer mit der ID ".$user->getId()." wurde erfolgreich hinzugefügt.";

Here, the so-called is Entity Manager for Doctrine instructed an object ( model saving). The Entity Manager manages models and serves as an interface to the database.

Web links

Individual evidence