Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it worth using Doctrine 2 with Zend Framework?

I know that some users use Doctrine 2 instead of Zend_Db in Zend Framework. But I don't know why. Why is Doctrine2 better than Zend_Db and why Zend_Db is not good?

Thanks

like image 934
user594791 Avatar asked Feb 02 '11 12:02

user594791


1 Answers

(7-Mar-2013) Disclaimer: This answer is probably now a bit out of date. I'm not keeping up with the PHP community at the moment and this comparison is between Doctrine ORM v2 and Zend Framework v1. This is an apples vs. oranges comparison because they're two different things.


Out-of-the-box Zend_Db is more just an enhanced Database Abstraction Layer on top of PDO, where as Doctrine 2 is a Object Relational Mapper (which sits on top of it's own DBAL).

Doctrine 2 is much better for more complicated domain layers, because all your business logic, persistence logic, etc are separated over multiple classes, so they don't serve multiple roles. Also, because you have more classes - that are cleaner and loosely-coupled - it makes testing them much easier.

Futhermore, you'll be writing only fraction of the SQL that you be using Zend_Db, because you can manipulate your entity objects and Doctrine translates those change to the database. The generated SQL also takes advantage of transactions which gives you a decent performance gain!

I'd recommend you read up on Domain-Driven Design to get a better understanding of why Doctrine 2 is so awesome.

Don't get me wrong though, you can do DDD with Zend_Db but it's not really there OOTB (because it's not an ORM), and wouldn't be nearly as powerful and full-featured like Doctrine 2.

like image 166
Cobby Avatar answered Nov 15 '22 17:11

Cobby