I have used Zend_Db and I found it very good, but why do some books and documentations advocate using Doctrine 2 over Zend_Db ? I am not an expert in ORM, but is there some functionality that Zend_Db can do and Doctrine ORM can't?
Which is more secure?
Experts who use both: which one do you advice me to use?
Is there any book for Doctrine 2?
..but is their some Functionality that the Zend_Db can do and ORM can't
No real functionality, per se; in the end, you can handle the persistence via ZDB and ORM or any other method. But using an ORM sometimes allows you to focus attention a bit more on your models and less on your persistence.
and is there any book for Doctrine 2 ??? not the documentations !
Actually, I find the official Doctrine2 documentation to be pretty good.
An additional thing that is useful in a Zend Framework app is a Zend application resource (like this one by Boris Guery) that allows you to set up Doctrine at bootstrap so you have easy access to the entity manager in your plugins, controllers, and other services. For an example that performs Doctrine2 bootstrap via _initXXX()
method, see the code in this project driven by Eddie Jaoude.
finally should I have to learn doctrine 1.2 before Doctrine 2 ?
Nope, Doctrine2 is distinctly different from Doctrine1.
and for expert who use both what u advice me to use ??
Well, I'm no expert. But I find Doctrine2 (which is something of a mapper-based approach to persistence) to be more natural than Doctrine1's ActiveRecord approach, more easily allowing my models to represent actual domain objects - users, posts, etc - rather than being gateways for object retrieval and persistence. By using the EntityManager
as the main avenue for persistence, I find it easier to structure other services that need persistence; I simply pass the EntityManager
as a constructor argument. Doctrine2's repositories provide a clean place to put custom queries.
Not that all this is impossible under ZDB or other ORMs; it's just that I find it straightforward with Doctrine2.
Summary: Doctrine2 is awesome. ;-)
Zend_Db is not an ORM. It is just a set of classes that implements database functionality.
Zend_Db_Table implements the Table Data Gateway design pattern. With this you can write a number of extension classes and build up your own object mapper but don't assume that Zend_Db is an 'out-of-the-box' ORM solution like Doctrine.
I've found Zend_Db to be less than ideal for writing complex object mappers but I do prefer it to ORMs as I feel as I have more control over how it behaves.
I remember reading somewhere that even the developers of Zend_Db weren't happy with the end result. In practice, I've found it clunky, slow and not really much of an improvement over using straight PDO to access the database.
Doctrine 2, whilst I have very little experience with it, seems to be built around much stronger concepts and is less likely to cause you issues in the future.
That said, this is very much a case of whatever works for you - if you already use Zend_Db, perhaps you're better off sticking with that rather than learning a new library.
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