PHP Classes

File: use_example_class.php

Recommend this page to a friend!
  Classes of Hensel Hartmann   Fast DB Class Generator   use_example_class.php   Download  
File: use_example_class.php
Role: Example script
Content type: text/plain
Description: demo usage of the example class - all options
Class: Fast DB Class Generator
Generate classes to access MySQL database tables
Author: By
Last change:
Date: 12 years ago
Size: 3,402 bytes
 

Contents

Class file image Download
<?php

/**
 * @author simpeligent.ch
 * @copyright 2012
 *
 * this file shows how to use the automatically generated classes
 * this example uses the included class "EXAMPLE-CLASS.class.php"
 *
 * to work with it, run the below SQL in your DB first
 *
 */

/*
if you want to test this class, you need the table and data in the DB
this class uses the following table:
CREATE TABLE IF NOT EXISTS `pages` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=21 ;

INSERT INTO `pages` (`id`, `name`) VALUES
(1, 'About'),
(2, 'News'),
(3, 'News Details'),
(4, 'DJs'),
(5, 'Shows'),
(6, 'Photos'),
(7, 'Photo Details'),
(8, 'Videos'),
(9, 'Artists'),
(10, 'Videos Details'),
(11, 'Artists Details'),
(12, 'Guestbook'),
(13, 'Links'),
(14, 'Advertise'),
(15, 'Contact'),
(16, 'AA_Test_Sections.php'),
(17, 'Channel-List'),
(18, 'Channel-Detail-Page');
*/


require_once('db.config.php');
require_once(
'EXAMPLE-CLASS.class.php');



// start class
   
$p = new Pages();
// attach the DB link
   
$p->db = connectDB::getConn();

// get all items of the DB with no filters and no debug
   
echo 'test 1: get all items of the DB with no filters and no debug <br />';
   
print_r($p->getList());

// get all items of the DB with no filters but debug
   
echo '<hr />test 2: get all items of the DB with no filters but debug<br />';
   
print_r($p->getList(NULL,NULL,1));

// get all items of the DB with some filters and debug
   
echo '<hr />test 3: get all items of the DB with some filters and debug<br />';
   
print_r($p->getList(' id>5 && id<12 ',NULL,1));

// get all items of the DB with some filters and debug
   
echo '<hr />test 4: get all items of the DB with some filters and debug<br />';
   
print_r($p->getList(Null,' ORDER BY name DESC LIMIT 3',1));

// get all items of the DB with some filters and debug
   
echo '<hr />test 5: get all items of the DB with some filters and debug<br />';
   
print_r($p->getList(' id>5 && id<12 ',' ORDER BY name DESC LIMIT 3',1));



// assign one item to an array - here, id=10
   
$a = $p->getObject(10);
    echo
'<hr />test 6: assign one item to an array - here, id=10<br />';
   
print_r($a);

// access an item directly - here, id=3
   
$p->getObject(3);
    echo
'<hr />test 7: access an item directly - here, id=3<br />';
   
print_r($p->_item);
    echo
'<br />id = '.$p->_item['id'];
    echo
'<br />name = '.$p->_item['name'];

// set an item property to a new value
   
$p->_item['name'] = 'test';
    echo
'<hr />test 8: set an item property to a new value<br />';
   
print_r($p->_item);
// write the updated values to DB by updating the last accessed object ($p->getObject($key))!
// here, id=3, debug is tuned on
    //$p->_updateDB(1);
// again id=3, debug is tuned off
    //$p->_updateDB();


// if you assigned some values to _item, you can save that as new object - debug is turned on
    //$p->createNewObject(1);

// if you assigned some values to _item, you can save that as new object - debug is turned off
    //$p->createNewObject();

// delete an object by it's key - debug is turned on
    //$p->deleteObject(19,1);

// delete an object by it's key - debug is turned off
    //$p->deleteObject(20);








?>