<h1>A_Db_Datamapper</h1>
<h2>Introduction</h2>
<p>The Datamapper maps properties from a class to fields in one or more database tables. It creates objects and loads associated database data in the object. Changes are tracked so you can save all changes back to the database with one call. </p>
<p>Say you have a User class and you want to map User objects to a user table. Here is the User class:</p>
<pre>class User {
	public $username = '';
	public $password = '';
	public $name = '';
}
</pre>
<p>Here is the database table:</p>
<pre>create table (
userid char(20),
passwd char(20),
full_name char(40)
};</pre>

<p>You would setup the mappings between the properties and fields like this:</p>
<pre>
// create datamapper with class name 'User' and table name 'users'
$Mapper = new A_Db_Datamapper(new My_Db(), 'User', 'users');

/ create the relationships between each property and field
$this->addMapping(new A_Db_Datamapper_Mapping('username', 'userid'));
$this->addMapping(new A_Db_Datamapper_Mapping('password', 'passwd'));
$this->addMapping(new A_Db_Datamapper_Mapping('name', 'full_name'));

// load/create User objects by key
$User1 = $Mapper->load('Steve');
$User2 = $Mapper->load('Sally');

// add new users to be inerted
$User5 = $Mapper->add(new User('Bill', 'xxx', 'William Smith'));

// write the changes and new users to the database
$Mapper->commit();
</pre>
