A persistence layer encapsulates the behaviour needed to make objects persistent.
Meaning to load, save and delete objects to and from persistent storage. In this case persistent storage means relational database. Database abstraction is provided by PEAR MDB2.
With MDB2_DataContainer2 and few lines of extra code you can implement Active Record Pattern (An object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data).
The class does not use any external configuration files. Extending class itself IS the configuration. All that is needed is to have matching propertyname – columname pairs in the class and the database table.
If the database schema changes, for example the developer adds a column foo to the table, all needed to do is to add a property name foo to the class which extends MDB2_DataContainer2.
There is no need to rewrite any internal SQL queries.
Here are some key features of "MDB2_DataContainer2":
· Simple API
Limitations:
· The class does not provide direct support for JOIN:s or table linking. For extreme cases it is still possible to pass hardcoded SQL queries. This usage is discouraged since it breaks the basic idea of using MDB2_DataContainer2.