The ZF quickstart provides an example of The Data Mapper pattern that seems to work reasonably well with ZF 1.x. It is not required that you implement a Data Mapper to use Zend_Db. You can get quite good functionality just using the DbTable models and the methods provided by Zend_Db_Table_Abstract.
To explain a bit:
Application_Model_Guestbook: would be a simple Domain Model (the object you interact with).
Application_Model_GuestbookMapper: would be the data mapper to map the database columns to the propeties of the domain model.
Application_Model_DbTable_Guestbook: is the gateway model that provides the connection between the database and the database adapter. This is where you can specify options for your database table and relationships with other tables.
It took me a little experience with ZF and Models before I figured out how the data mapper applied to my applications. I really began to understand how these pieces fit together when I started building objects that depended on more then one database table.
'
You'll notice that a number of experienced ZF developers recommend Doctrine or some other ORM right away, for them that is probably the correct choice (and seems to be reflex for some). I just feel that I shouldn't start using an ORM until I understand at least the basics of what that ORM is doing.
[EDIT]
fetchAll() equivalent method in base mapper class, pass in instance of Zend_Db_Table_Abstract to the __constructor
public function findAll($order = NULL) {
$select = $this->_getGateway()->select();
if (!is_null($order)) {
$select->order($order);
}
$rowset = $this->_getGateway()->fetchAll($select);
$entities = array();
foreach ($rowset as $row) {
//abstract method required in each table mapper, this instantiates the domain model
$entity = $this->createEntity($row);
//identiy map allows lazy loading of certain members
$this->_setMap($row->id, $entity);
$entities[] = $entity;
}
//returns an array of domain models instead
return $entities;
}
the createEntity() method from of my table specific mappers
public function createEntity($row) {
$data = array(
'id' => $row->id,
'name' => $row->name,
'art' => $row->art,
'year' => $row->year,
);
$entity = new Music_Model_Album($data);
//set artist id to reference map for lazy loading
$entity->setReferenceId('artist', $row->artist_id);
return $entity;
}
Good Luck