I was going through the Zend Framework quickstart tutorial, and in their demo code they use a data mapper which uses Zend_DB_Table to access the database (see: http://framework.zend.com/manual/en/learning.quickstart.create-model.html). It seems that Zend_DB_Table doesn’t use prepared statements or provide a way to use transactions though. Therefore, I’m leaning towards just using a datamapper directly with a zend_db_adapter. With that in mind, can someone advise as to the situations where Zend_DB_Table would be advantageous? Appreciate your input! Cheers.
I was going through the Zend Framework quickstart tutorial, and in their demo code
Share
In general, I see
Zend_Db_Tableas a quick and easy way to do single-table queries.You can surely do joins with
Zend_Db_Table, but since the class is targeted towards a specific table (after all, it is intended as a Table Data Gateway implementation), all such joins always feel – to me, at least – like an unnatural graft. In that case, I always tend towards straight adapter-based queries with joins, that could include your transaction handling.Of course, in either case, it is certainly desirable to put all of this behind a model or mapper or service layer. Then, as you change these implementation details- say, start out with a
Zend_Db_Tableimplementation, but later realize you need to join data from a another table, so you move to adapter-based queries – none of this will affect consumers of the model/mapper/service.Hope this helps.