PDO vs Doctrine


Work with system development in PHP , more focused on e-commerce . Currently I use PDO to perform my connection to the database, but out of curiosity I decided to search on Doctrine , because when I was developing in C # in NHibernate , which are Framework that take care of this part of the connection and facilitate queries, among others.

But my question would be regarding the performance of Doctrine compared to PDO , and the cost of memory is most likely higher in Doctrine and the processing time a bit slower.

What are the Advantages and Disadvantages of using Doctrine instead of PDO ?     

asked by anonymous 24.03.2016 / 12:54

2 answers



  • It allows you to work on a pure OO model without having to worry about how your OO "X" entity maps to the relational entity "Y".
  • Instead of needing to write "raw" SQL you have an OO API for all operations on the database (SELECTS, INSERTS, etc.).
  • Reduction of boilerplate : Although SQL is an excellent language in the domain for the which was built it ends up being very repetitive in building common applications, you make tons of SELECTS and INSERTS almost identical and all being written as strings. Boring, repetitive and highly error prone.


  • Performance: ORMs (Doctrine in this case) are slow compared to "raw" SQL (the PDO), it is no use saying that the framework is very optimized and mature, in the end the performance suffers. Not that it is an intolerable overhead, you can make an application with excellent performance using the doctrine, the problem is that as the complexity of the queries made it grows, the performance suffers more and more and eventually you will have to worry about optimization, and the problem here is that optimizing an ORM is not as simple as pure SQL optimization, you need to understand how ORM works (how it generates queries) in addition to understanding how SQL works, so in the end this breaks the promise that you can escape the relational model and work only in OO.
  • Complex Query Expression: SQL is a language that was created specifically for queries (Structured Query Language), and it is great at it. Since OO is another story, a supposed representation of the real world in the form of computational objects, it is a generic model that although it can be used for conducting queries is not ideal for such, a good example is that ORMs are famous for having Strange APIs for JOINS. In the end SQL is greater than OO in query expression and this is very evident in complex cases (queries that involve many entities for example).
24.03.2016 / 16:09

Basically, the advantage is entity mapping and data persistence, in addition to having a great advantage of caching, it allows you to have a maintenance facility using only entities. When using Doctrine, with ORM, we are talking about a much more mature and consistent code. Although the doctrine is a bit slower in its first run, when it needs to create the cache, you gain in performance when it comes to a database with a lot more volume. But I do not disqualify the PDO, you can even use the two together, one does not disturb the other, but everything will depend on how you will design your project. I would not rule out its use when we are talking about a system with a lot of access and data movement, but would not adopt a less robust architecture, I do not see many advantages in this regard.

24.03.2016 / 15:28