Introduction

Introduction --  What DB_DataObject can do

Introduction

Db_DataObject is a SQL Builder and Data Modeling Layer built on top of PEAR DB, It main purpose is to

The DB_DataObject is rarely accessed directly, it is intended to be the base class which you can extend to put the code specifically relating to a particular database table. Below is an example of how you can use the end result (and extended class),

The above example illustrates the two components of the DataManager, By setting the options, all the core objects will be able to auto load the data definitions from a generated ini file, and know how to access the database. (multiple databases are supported - see section on configuration)

The later half illustrates how to query and get the result for a single row. The $person->get() would connect to the database, perform the query, fetch the result and assign the objects variables to the data returned from the query.

In the above example, this query would be performed.

SELECT * FROM person WHERE id=12;

To make a change to the Database you would just change the value of the objects variables and call the update method.

$person = new DataObjects_Person;
        $person->get(12);
        $person->name = 'Fred';
        $person->update();

The Package includes a number of tools to make building the extended classes and configuration file, Once you have made your extended classes, the idea is that any data manipulation/calculation that relates to this table, or how this table interacts with other data is placed inside the extended class.

require_once 'DB/DataObject.php';

    class DataObjects_Person extends DB_DataObject {

        function &listMembership()
        {
            $members = new DataObjects_Members();
            $members->person_id = $this->id;
            $members->find();
            return $members;
        }
    }

In this example the Person object asks the Members Object to list all records that have the column person_id equal to the current instance's id.