I'd like an ActiveRecord support implementation consisting of a class builder, class instance ServerBehavior and Datasource support.
The ADODB library (used by numerous PHP applications including the opensource Dreamweaver PHP ServerModel PhAkt) contains an Object Relation Mapping (ORM) implementation called ADOdb_Active_Record.
ActiveRecord in the PhAkt servermodel, sample code depends on ADOdb V4.92a released 29 Aug 2006, which can be obtained from http://adodb.sourceforge.net
ORM allows us to map database fields onto custom classes as per the following example
<?php
//PhAkt Connection include
require_once('Connections/adodb_test.php');
//ActiveRecord include
require_once('adodb/adodb-active-record.inc.php');
//ActiveRecord database initialization
ADOdb_Active_Record::SetDatabaseAdapter($adodb_test);
// definition of custom class
class test extends ADODB_Active_Record {
var $title;
function sayHello(){
return "Hello ".$this->title;
}
}
// create a new instance of our custom class
$t = new test();
// load data from database into custom class using SQL where clause
// activerecord pluralizes the class name thus loading data from table "tests"
$t->Load("title='test'");
// print a property
echo $t->title;
// call a method
echo $t->sayHello();
// change a propery
$t->title = "test";
// save changes
$t->Save() or die($adodb_test->ErrorMsg());
?>