Prev | Current Page 152 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

manning-sandbox.com/forum.jspa?forumID=329
Table 5.4: Deleting rows with Zend_Db_Table and Zend_Db_Adapter compared
Zend_Db_Adapter
// delete a user
$table = 'users';
$where = 'id = 2';
$db->delete($table, $where);
Zend_Db_Table
// delete a user
$users = new Users();
$where = 'id = 2';
$users->delete($where);
1.4
The $where clause in delete() for both Zend_Db_Table and Zend_Db_Adapter does not quote the values
for us, so if we were to delete based on anything other than an integer, then we would have to use quote(),
quoteInto(). For example, to delete all users who live in London:
$users = new Users();
$db = $users->getAdapter();
$where = $db->quoteInto('town = ?', 'London');
$users->delete($where);
We have now looked at all the major database operations that can be done using the Zend_Db_Adapter
and Zend_Db_Table components. When fitting in database operations into a Model-View-Controller
application, they usually fit as part of the Model. This is because the Model is where the business logic of your
application is and the data stored in a database is very much related to the business of the application. We will
now look using Zend_Db_Table based objects within a Model and, possibly more importantly, how to test it.
5.3 Using Zend_Db_Table as a Model
Zend_Db_Table is usually the point where we integrate the Zend_Db component into a Zend Framework
MVC application.


Pages:
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
stolarka aluminiowa częstochowa Potopek uchwyt lcd wyciągarki hotele londyn