Prev | Current Page 142 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"


Zend_Db_Select
Zend_Db_Select allows for using PHP to build database query statements in the comfortable language of PHP
rather than SQL.
The Zend_Db_Select provides a number of advantages. The most important ones are:
Automatic quoting of meta-data (table and field names)
Object oriented interface can provide for easier maintenance
Helps to promote database independent queries
Quoting of values to help reduce SQL injection vulnerabilities
Licensed to Menshu You
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
A simple query using Zend_Db_Select is shown in Listing 5.2:
Listing 5.2: Creating a Zend_Db_Adapter instance using the factory function Zend_Db::factory()
$select = new Zend_Db_Select($db); #1
$select->from('users');
$select->where('date_of_birth > ?', '1980-01-01');
$result = $select->query(); #2
(annotation) <#1 Attach the Zend_Db_Adapter to the select object>
(annotation) <#2 execute the query>
One very useful feature of Zend_Db_Select is that you can build the query in any order. This differs from
standard SQL in that you must have each section of your SQL string in the correct place. For a complex query,
the maintenance required is simplified using Zend_Db_Select.


Pages:
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
wynajem samochodów kraków ogłoszenia Perfumy black jack inteligentny dom