This would be incorrect as at the table level, you never know
which record (or records!) need updating. At the Zend_Db_Table_Row level however, it makes perfect sense.
Looking at Zend_Db_Table_Row, we discover that this functionality is already written for us as there is a
function called save(). It is used as shown in Table 5.3.
Table 5.3: Saving with Zend_Db_Table_Row
Inserting a new record
$users = new Users();
$row = $users->fetchNew();
$row->first_name = 'Ben';
$row->surname = 'Ramsey';
$row->save();
Updating a record
$users = new Users();
$row = $users->fetchRow('id=2');
$row->first_name = 'Ben';
$row->surname = 'Ramsey';
$row->save();
1.3
In this case, the entirety of the differences between inserting a new record and updating a current one are
hidden from us. This is because the Zend_Db_Table_Row object works at a higher level abstraction.
5.2.4 Deleting records with Zend_Db_Table
As you would expect, deleting works exactly the same as inserting and updating only we use the delete()
function. The delete() function is available in both Zend_Db and Zend_Db_Table and as with insert and
update, the usage is very similar between the two classes as shown in Table 5.4.
Licensed to Menshu You
Please post comments or corrections to the Author Online forum at
http://www.
Pages:
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163