FWIW, the book is really eye-opening. But Martin also says he would recommend you "purchase" a data mapping layer rather than code your own...but you can do simple stuff...but if its so simple then an ActiveRecord is a better choice...and hence ruby, cake, etc, all seem to use ActiveRecord.
The best "mapper" I've seen for php was Doctrine ([url]http://www.phpdoctrine.org)[/url], but I found it difficult to use because the phpdoc API is wrong in places, making using the classes impossible; and I generated the php api from the Doctrine sources directly. That said, my own phpdoc comments are probably not 100% accurate, as it really requires another set of eyes to verify everything is correct.
Really, although a code sample is nice, if you have the "interface" you can probably fill in the blanks:
function insert($data_obj)
{
// create and execute SQL to write $data_obj to DB, which is simple if
// $data_obj maps to a single table
}
And I would add finder methods to the mapper as well
function find($id)
{
// extract, construct and return instance of data object with ID $id
}
function find_where($where)
{
// now it gets trickly...pear and PDO (same thing?) have some interesting approaches
// but I prefer to make $where be an assoc. array of column names => values
// so $where = array('username'=>'Bill Gates') makes an SQL statement
// with a where clause: "WHERE `username` = 'Bill Gates'
}
I've done this, sort of, and you can see the PHP5 code here in the DB package look at DAO and DTO classes:
http://phpfunk.com/software/api/
There is some "cruft" in my code, but it does work. That is, I originally had the class work one way (try to use a table naming convention to map tables to object classes) but that didn't last too long, so now the DAO takes the name of the class and the table name as constructor parameters.