Abstract SQL Table to Object: Map table rows to objects with Active Record

Recommend this page to a friend!
  Info   View files (5)   Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
50%Total: 3,254 All time: 1,068 This week: 314
Version License PHP version Categories
parentdbtoclass 1.1Freeware4.3Databases, Design Patterns
Description Author

This package uses the Active Record design pattern to map database table records to objects.

It provides a base class from which all classes that map database tables should inherit.

The sub-class should define the table it is wrapping, the primary key field and variables to store the table field values.

The base class can query the database to retrieve the list of fields of the specified table. It can also perform all the basic operations of INSERT, SELECT, UPDATE and DELETE the mapped table rows.

This package uses ADODb database abstraction package so it can support multiple databases.

Picture of Sergey Shilko
Name: Sergey Shilko <contact>
Classes: 4 packages by
Country: Belarus Belarus
Age: 35
All time rank: 3392 in Belarus Belarus
Week rank: 261 4 in Belarus Belarus

coredb.class.php      - DB OBJECT HANDLER (REQUIRE ADODB) (include dirname(__FILE__)."/adodb/adodb.inc.php";)
parent.dbtoclass.php  - Database Table handler
sample.php	      - Sample handler of table 'catalog';

Handler Usage >>> 
For example we have mysql table 'catalog', with fields 'id','title','price':
What we do is :
1)Create Child class of parent.dbtoclass.php (class Foo extends dbtoclass ...) see sample.php
2)Make same fields in class as in db i.e.: see sample.php
3)you can call parent:::makeGetSetMethods() to get All get*,set* methods for all your class fields (title,price...)
4)Also you may get the list of changed values from parent class (value/field that waws realy cchanged, for logging)

/* Update existing  >>> */

$foo = new Foo($db); 	       	     #Initialize object with DB object
$foo->checkout(25);           	     #load item details to class
$foo->setNewValues($hash_array);    #update class with new values
$foo->commit();               	     #Commit all changes to db and write log
$foo->finish();               	     #Finish work with the class.

/* <<< */

/* Create new  >>> */

$foo = new Foo($db); #Initialize object with DB object
$foo->create($hash_array);               #Commit all changes to db and write log
$foo->finish();               #Finish work with the class.

/* <<< */

/* Delete record */

$foo = new Foo($db); #Initialize object with DB object
$foo->delete(25);			   #Delete item
$foo->finish();               #Finish work with the class.
File Role Description
coredb.class.php Class DatabaseHandler
j-coredb.class.php Class Joomla CMS 1.0.12 Databasehandler Wrapper
parent.dbtoclass.php Class Parent Database to Class handller
readme.txt Doc. Simple Readme First File
sample.php Example Sample child of main class

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:1,068
This week:314
 User Ratings  
 All time

For more information send a message to info at phpclasses dot org.