Login   Register  
PHP Classes
elePHPant
Icontem

File: example.gen.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of zengwenjie  >  genpo  >  example.gen.php  >  Download  
File: example.gen.php
Role: Example script
Content type: text/plain
Description: how to genarate a class base one table
Class: genpo
Generate class to access table records as objects
Author: By
Last change:
Date: 2008-09-24 23:45
Size: 1,065 bytes
 

Contents

Class file image Download
<?php 

include "class.genpo.php";
/*
CREATE TABLE IF NOT EXISTS `compinfo` (
  `id` bigint(20) NOT NULL auto_increment,
  `mylink` varchar(100) NOT NULL,
  `compname` varchar(500) default NULL,
  `address` varchar(100) default NULL,
  `post` varchar(100) default NULL,
  `email` varchar(100) default NULL,
  `phone` varchar(500) default NULL,
  `zip` varchar(100) default NULL,
  `memo` varchar(100) default NULL,
  `intime` date NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=636 ;
*/

$dbserver="localhost";
$dbuser="annie";
$dbpass="annie";
$link=mysql_connect($dbserver,$dbuser$dbpass);
$dbname="annie";
$tablename="compinfo";

$fields  =  mysql_list_fields (  $dbname ,  $tablename ,  $link );
$columns  =  mysql_num_fields $fields );
$fieldnames = array();
for ( 
$i  =  ;  $i  <  $columns ;  $i ++) {
    
$fieldnames[]=  mysql_field_name $fields ,  $i )   ;
}

$g = new genpo($tablename,$fieldnames);
echo 
"<textarea rows=100 cols=100>";
echo 
$g->genpo() ;
echo 
"</textarea>";
?>