Zend Framework: Proper way to interact with database?

后端 未结 3 1173
孤独总比滥情好
孤独总比滥情好 2021-02-02 02:17

I\'m fairly new to the Zend Framework and MVC and I\'m a bit confused by Zend_DB and the proper way to interact with the database.

I\'m using the PDO MySQL adapter and h

3条回答
  •  有刺的猬
    2021-02-02 02:20

    In general, people prefer to access the database through the Table and Row objects, to match their habits of object-oriented programming.

    The OO approach is useful if you need to write code to transform or validate query inputs or outputs. You can also write custom methods in a Table or Row class to encapsulate frequently-needed queries.

    But the object-oriented interface is simplified, unable to perform all the types of database operations you might need to do. So you can delve deeper and run a SQL query against the Zend_Db_Adapter methods like query() and fetchAll() when you require finer control over your SQL.

    This is pretty common for object-oriented interfaces to databases. An OO layer that could duplicate every SQL feature would be insanely complex. So to compromise, an OO layer usually tries to provide easy ways to do the most common tasks, while giving you the ability to go under the covers when necessary.

    That's a very general answer to your very general question.

提交回复
热议问题