DB_DataContainer 1.3.1 review

by rbytes.net on

DB_DataContainer is a PEAR compliant database persistence layer and data encapsulation class

License: BSD License
File size: 9K
Developer: Mika Tuupola
0 stars award from rbytes.net

DB_DataContainer is a PEAR compliant database persistence layer and data encapsulation class. A persistence layer can encapsulate the behaviour needed to make objects persistent like for exemple: to load, save and delete objects to and from persistent storage. Currently the only supported persistence mechanisms are relational databases. Database abstraction is provided by PEAR DB.

Data encapsulation is provided by overloaded accessor methods. This means that if you have a property named $foo and you do not write getFoo() and setFoo() methods in the extending class yourself, they will be automatically provided by DB_DataContainer.

As a result of the provided persistence mechanism and data encapsulation DB_DataContainer together with few lines of extra code can be used to implement the Active Record Pattern as described by Martin Fowler:

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. The extending class itself IS the configuration. All you need to take care about is to have matching propertyname - columname pairs in the class and the database table.

If your database schema changes, for example you add an column foo to the table, all you need to do is to add a property name foo to your class which extends DB_DataContainer. There is no need to rewrite any internal SQL queries.

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 DB_DataContainer.

Here are some key features of "DB DataContainer":
Simple API
Persistence mechanism encapsulation. You only need to call load(), save() or delete(). Note that there are no separate methods for INSERT and UPDATE. save() figures itself out which query to use.
Overloaded accessor methods for class properties without such methods.
PEAR DB supported databases as persistence mechanisms (tested with Postgres, MySQL, MSSQL and SQLite).
Multi-object actions provided by a static getObjects() call.
Possibility to use hardcoded SQL queries in multi-object actions.
Regression tests.
Supports PHP4 and PHP5 (starting from version 1.3.0)

What's New in This Release:
This release fixes problems with protected and private data members when using PHP5.

DB_DataContainer 1.3.1 search tags