Using DB Table and Row Patterns
Why use an object-oriented API to construct SQL instead of writing SQL directly? Sometimes advanced SQL, or database-specific SQL queries are difficult to create using an object-oriented API. For these uncommon cases, programming directly in SQL may be more appropriate. For more typical cases, the Zend Framework's data abstraction components offer several possible advantages.
However, for many other situations, using the object-oriented API provided by the ZF database abstraction components provides benefits, including:
- Portability: For the ZF Zend_Db* components' supported range of queries, the logic required to produce database-specific queries is encapsulated within these Zend_Db* components. The Zend Framework community helps maintain and develop this logic, reducing the effort required from ZF developers to make their applications portable to other databases.
- Standardization and Consistency: Applications developed using the ZF database components follow conventions and standard practices, with the ZF API providing a form of standardization. Developers familiar with these components may find a lower learning curve when working with other ZF applications, compared to applications not following a known database abstraction standard.
- Ease of Use: Some developers find the object-oriented API easier to use than writing the SQL themselves.
- Dynamic Query Generation: Some complex queries must be generated within application logic, where parts of the query dynamically depend various computations, and may differ substantively for different conditions. The query building portions of Zend_Db* components allow out-of-order invocation of the query building methods, but the final resulting SQL query is assembled in the correct order.
- Security: The Zend_Db* components provide mechanisms for defining parameters in queries, which makes it possible for Zend_Db* to help properly quote data dynamically inserted into queries.
Next Section: 11. Localization
ZF Home Page
Code Browser
Wiki Dashboard