PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Christian Velin   DbCodeBuilder   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Code examples
Class: DbCodeBuilder
Generate code to access databases as data objects
Author: By
Last change:
Date: 17 years ago
Size: 2,236 bytes
 

Contents

Class file image Download
<?php
/* How to use the DbCodeBuilder and generate DAO's and VO's on the fly [START] */
include('AccessBuilder.class.php');
include(
'VOFormatter.class.php');
include(
'DAOFormatter.class.php');

$builder = new AccessBuilder('host','username','password','db');
$builder -> setTables();

$tables = $builder->getTables();
$columns = $builder->getColumnInfo();

$voFormatter = new VOFormatter($tables, $columns);
print
$voFormatter -> getOutput();

$daoFormatter = new DAOFormatter($tables, $columns);
print
$daoFormatter->getOutput();
/* How to use the DbCodeBuilder and generate DAO's and VO's on the fly [END] */



/*=================DB structure for the sample code below [START]================
CREATE TABLE `user` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `username` varchar(120) collate utf8_unicode_ci NOT NULL default '',
  `password` varchar(40) collate utf8_unicode_ci NOT NULL default '',
  `rank` int(2) NOT NULL default '99',
  `active` tinyint(4) NOT NULL default '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;
=================DB structure for the sample code below [START]================*/



/* How to use the generated code to create a new record [START] */
require('User.VO.php');
require(
'User.DAO.php');

$vo = new UserVO();
$vo->setId(0); //A new record MUST ALWAYS be set to 0.
$vo->setUsername('a_user_name');
$vo->setPassword(sha1('a_password'));
$vo->setRank(99); // A parameter to keep track of user access levels.
$vo->setActive(0); // A parameter to see if someone registers but doesn't validate registration.

$link = mysql_connect('host', 'user', 'password');
mysql_select_db('db', $link);

$dao = new UserDAO($link);
$dao->save($vo);
/* How to use the generated code to create a new record [END] */

/* How to use the generated code to update an existing record [START] */
$vo->setPassword(sha1('a_new_password'));
$dao->save($vo);
/* How to use the generated code to update an existing record [END] */



/* How to use the generated code to delete an existing record [START] */
$dao->delete($vo);
/* How to use the generated code to delete an existing record [END] */
?>