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
(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With