Hi..
ORM Layer usually takes care of persisting your objects into database as well as retrieving those objects from database.
Lets take an example: you might have a class called Person, a class called Account and a class called Group. Each person would own one Account and they would have the possibility of belonging to many groups. This is a very simple example and you could write all the necessary methods by hand (retrieving all persons and their accounts, saving person's account etc.) or you can skip this phase (which in big projects can be very big phase) and use one of the availible ORM tools like (EZPDO, Propel or Doctrine). Personally I would recommend Doctrine although as its creator my opinion is clearly biased 
PHP Code:
class Person extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("name","string",200);
}
public function setUp() {
$this->hasMany("Person","GroupPerson.person_id");
$this->ownsOne("Account","Account.person_id");
}
}
class Account extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("amount","integer",11);
$this->hasColumn("person_id","integer",11);
}
}
class Group extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("name","string",200);
}
public function setUp() {
$this->hasMany("Person","GroupPerson.person_id");
}
}
class GroupPerson extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("group_id","integer",11);
$this->hasColumn("person_id","integer",11);
}
}
// USAGE:
$person = new Person();
$person->name = "JustMe";
$person->Account->amount = 1000;
$person->save();
/** executes two prepared queries and wraps them into transaction the
* queries would look like: INSERT INTO person (name) VALUES (?)
* INSERT INTO account (person_id, amount) VALUES (?,?)
*/
// retrieve all persons and accounts ($session is Doctrine_Session object):
$persons = $session->query("FROM Person.Account");
Bookmarks