PHP Classes

File: demo8-orm.php

Recommend this page to a friend!
  Classes of Bob Gombocki   PersistClass   demo8-orm.php   Download  
File: demo8-orm.php
Role: Example script
Content type: text/plain
Description: Custom column mapping
Class: PersistClass
DB access wrapper & storing objects in DB tables
Author: By
Last change: added web tutorial info
Date: 15 years ago
Size: 927 bytes
 

Contents

Class file image Download
<?php

/*
    http://coolpenguin.net/persistclass
    for updates, documentation, tutorials
*/

// connect to database (executing demo 1)
require('demo1-connection.php');

// defining persistence class with mappign information
class TestTable extends PersistClass {
    protected
$sqlTableName = 'TESTTABLE';
    protected
$sqlPrimaryKey = 'testid';
    protected
$sqlColumnToFieldMapping = array('testcolumn' => 'testcolumncalleddifferently');
}

// preparation for the demo (ensuring there is a row / object with id = 1)

try {
   
$id = 1;
   
$newTestTable = new TestTable($id);
} catch(
NoResultException $e) {
   
$newTestTable = new TestTable();
   
$newTestTable->setId($id);
   
$newTestTable->insertDb();
}


$id = 1;
$testObj = new TestTable($id);
$testObj->getData('testcolumncalleddifferently');
$testObj->setData('testcolumncalleddifferently', 'grrrrr');
$testObj->updateDb();

echo
'Test successful';

?>