Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Db (standard or table gateway) vs Doctrine in Zend 2 - Pros/Cons

Zend DB (standard way or table gateway) vs Doctrine in Zend 2. Some might say it’s apple vs orange comparison but I would say since they are substitutes (we use one between two) so it can be compared (as requirements are not always crystal clear).

When I started Zend 2 since documentation, books, tutorials were based on Zend DB or Table Gateway, I used it but I was not happy with ways when we have to work on 2, 3 or more tables joins (multiple table gateway adapters) so I switched to Doctrine ORM (also reading so many saying “doctrine is good for large project”). I was already using doctrine in symfony projects so was not difficult but I also didn’t like doctrine in instance like complex joins between entities (extra works), especially slowness and extra memory compared to Zend DB.

Now I am really confused what should I do? So what do you guys suggest?

From my analysis:

Table Gateway

Pros

  • Lightweight (keep things simple)
  • Native to Zend (better support now and for future updates)
  • More documentation-books
  • Better community or user support (as it is what many are working on)
  • Close of database-tables (I am good in SQL. So feel good)
  • More flexible
  • Easier to use other doctrine native features such as ACL

Cons:

  • Table joins (more complex)
  • Primitive in some context
  • Handling multiple table gateway instance is difficult.

Doctrine

Pros

  • More classes-loosely coupled—better control
  • Brings all advantages of using ORM
  • Lots of work already on doctrine itself (tutorials-documentations) which works most of the time
  • Less reliance on database
  • Caching (but also possible with Zend DB Table Gateway)

Cons:

  • More memory and slower (compared to Zend DB Table Gateway) for medium project
  • Adds complexity (extra files+ configurations + its own conventions)
  • Sometimes overkill for medium projects
  • More work in many to many relationships between entities or complicated joins
  • Extra work YAML-Schema
  • Less tutorials-books-user support on Zend + Doctrine

Any others? ( for both)

So, in light of these, which one do you suggest? Working on generic CMS that I can extend.

or why Zend DB cannot/should not be used in larger projects?

I found some discussion here but not as per its pros/cons analysis.

like image 286
TheGooooogle Avatar asked Mar 14 '15 11:03

TheGooooogle


People also ask

How to get started with Zend\DB\tablegateway?

The quickest way to get up and running with Zend\Db\TableGateway is to configure and utilize the concrete implementation of the TableGateway. The API of the concrete TableGateway is: The concrete TableGateway object practices constructor injection for getting dependencies and options into the instance.

What features does Zend\dB have built-in?

There are a number of features built-in and shipped with Zend\Db: GlobalAdapterFeature: the ability to use a global/static adapter without needing to inject it into a TableGateway instance. This is more useful when you are extending the AbstractTableGateway implementation:

What is the use of select() method in Zend?

The select () method takes the same arguments as Zend\Db\Sql\Select::where () with the addition of also being able to accept a closure, which in turn, will be passed the current Select object that is being used to build the SELECT query. The following usage is possible:

What is the tablegateway concrete implementation?

The TableGateway concrete implementation simply adds a sensible constructor to the AbstractTableGateway class so that out-of-the-box, TableGateway does not need to be extended in order to be consumed and utilized to its fullest.


1 Answers

I did the reverse. I removed Doctrine 2 and switch to Zend DB 2, that improves our queries by a factor of 5x, then we're able to customise some parts of Zend DB table gateway, and we gain 5x more performance on queries (almost as native).

I would say do not use Doctrine if you're gone have large datasets. And remember doctrine consumes a lot of resources.

like image 169
albanx Avatar answered Sep 22 '22 17:09

albanx