ADODB PHP ActiveRecord
Please note this is a request for an article explaining the usage of 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
The ADODB library (used by numerous PHP applications including the opensource Dreamweaver PHP ServerModel PhAkt) now contains an Object Relation Mapping (ORM) implementation called ADOdb_Active_Record.
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 {
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());
?>
Comments
Be the first to write a comment
You must me logged in to write a comment.