PHP Classes
Icontem

File: index.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Christian Velin  >  DbCodeBuilder  >  index.php  
File: index.php
Role: Example script
Content type: text/plain
Description: Code examples
Class: DbCodeBuilder
Generate code to access databases as data objects
 

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] */
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products