PDO vs Doctrine

Asked

Viewed 792 times

4

Work with systems development in PHP, more focused on e-commerce. Currently I use the PDO to make my connection to a database, but out of curiosity I decided to search about the Doctrine, because when it developed into C# used Nhibernate, who are Framework that take care of this part of the connection and facilitate consultations, among others.

But my doubt would be regarding the performance of Doctrine in relation to the PDO, the memory cost is very likely to be higher in the Doctrine and processing time a little slower.

What would be the Perks and Disadvantages in using the Doctrine instead of PDO?

2 answers

4


Perks:

  • Allows you to work on a purely OO model without having to worry about how your entity OO "X" maps to the relational entity "Y".
  • Instead of having to write "raw" SQL you have an OO API for all operations in the database (SELECTS, INSERTS, etc).
  • Reduction of Boilerplate (did not find a suitable term in English): Although SQL is an excellent language in the domain for which it was built it ends up being very repetitive in constructing common applications, you make tons of SELECTS and INSERTS almost identical and everything being written as strings. Boring, repetitive and highly error-prone.

Devantagens:

  • Performance: Orms (Doctrine in the case) are slow compared to "raw" SQL (the PDO), no use saying that the framework is very optimized and mature, in the end the performance suffers. Not that it’s an intolerable overhead, you can make an application with excellent performance using Doctrine, the problem is that as the complexity of queries made generally grows performance suffers more and eventually you will have to worry about optimization, and the problem there is that optimizing a ORM is not as simple as optimizing pure SQL, you need to understand how the ORM works (how it generates queries) in addition to understanding how SQL works, so ultimately this breaks the promise that you can escape the relational model and work only on OO.
  • Expression of complex queries: SQL is a language that was created specifically to make queries (Structured Query Language) and she’s excellent at it. While 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 to perform queries is not ideal for this, A good example is that Orms are famous for having strange Apis to do JOINS. In the end SQL is superior to OO in the query expression and this is quite evident in complex cases (queries involving many entities for example).
  • And what would be your tip, for the use or not use of Doctrine for an Ecommerce?

  • @Leonardopatricio in the end depends on your taste, does not have a direct answer. I particularly make a hybrid use, Orms for simple tasks like INSERTS, UPDATES and trivial SELECTS that only involve a table and from the moment I need to do something more complex where the ORM API starts to get "exotic" I write pure SQL.

  • Vlw by tip, I was thinking of something like this too, simple tasks with Doctrine and complex in PDO.

0

Basically, the advantage is the mapping of the entities and the persistence of the data, besides having a great advantage of caching, it allows you to have a maintenance facility, using only the entities. When you use Doctrine, with ORM, we’re talking about a much more mature and consistent code. Although Doctrine is a little slower in its first run, when it needs to create the cache, you win in performance, when it comes to a database with much 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 many accesses and data mobility, but would not adopt for a less robust architecture, I do not see many advantages in this sense.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.