Prev | Current Page 149 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

As we are working at a higher abstraction level with
the table, fetchAll() also works at the higher level as shown by its signature:
public function fetchAll($where = null, $order = null,
$count = null, $offset = null)
The function will handle creation of the SQL statement using Zend_Db_Select for us; we just need to
specify the parts we are interested in and it will handle the rest. For example, to select all female users born
from 1980:
$users = new Users();
$where = array('sex = ?' => 'F',
'date_of_birth >= ?'=>'1980-01-01');
$rows = $users->fetchAll($where);
5.2.3 Inserting and updating with Zend_Db_Table
Inserting and updating with Zend_Db_Table is very similar to the usage with Zend_Db_Adapter except that
this time we know the table already. Table 5.1 shows exactly how similar.
Table 5.1: Inserting with Zend_Db_Table and Zend_Db_Adapter compared
Zend_Db_Adapter
// insert a user
$table = 'users';
$data = array(
'date_created' => date('Y-m-d'),
'date_updated' => date('Y-m-d'),
'first_name' => 'Ben',
'surname' => 'Ramsey'
);
$db->insert($table, $data);
$id = $db->lastInsertId();
Zend_Db_Table
// insert a user
$users = new Users();
$data = array(
'date_created' => date('Y-m-d'),
'date_updated' => date('Y-m-d'),
'first_name' => 'Ben',
'surname' => 'Ramsey'
);
$id = $users->insert($data);
1.


Pages:
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
mieszkania na sprzedaż kraków Uwodzenie szkoły policealne Kawałek po kawałku wentylatory