Rob Allen, Nick Lo, and Steven Brown
"Zend Framework in Action"
1
Licensed to Menshu You
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
As you see from Table 5.1, exactly the same process is used, except that with Zend_Db_Table, we already
know the table??™s name and we get the id of the newly inserted record back directly. Updating a database row
follows the same concept as shown in Table 5.2.
Table 5.2: Updating with Zend_Db_Table and Zend_Db_Adapter compared
Zend_Db_Adapter
// update a user
$table = 'users';
$data = array(
'date_updated' => date('Y-m-d'),
'first_name' => 'Ben',
'surname' => 'Ramsey'
);
$where = 'id=2';
$db->update($table, $data, $where);
Zend_Db_Table
// update a user
$users = new Users();
$data = array(
'date_updated' => date('Y-m-d'),
'first_name' => 'Ben',
'surname' => 'Ramsey'
);
$where = 'id=2';
$users->update($data, $where);
1.2
Note that you need to quote any values and identifiers in the SQL expression used for the where clause.
This is done using the database apdapter??™s quote(), quoteInto() and quoteIdentifier() methods.
Similarities between inserting and updating
The similarities between inserting and updating lead to the conclusion that somehow it might be worth having
a single ???save??? function in Zend_Db_Table.
Pages:
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162