PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Stephen P   Class Generator for MySQL Tables   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example Script, shows you how to use this class.
Class: Class Generator for MySQL Tables
Generate classes to access MySQL database tables
Author: By
Last change:
Date: 15 years ago
Size: 1,852 bytes


Class file image Download
  Example file for classGenerator.class.php (ClassGenerator Class)
  Author: Stephen Powis
  Date: March 2008
  This Example assumes you want to create a class for the following mysql DB table structure,
  but you should be able to tweak this example easily to fit whatever table structure you have.
   CREATE TABLE `userTable` (
    `user_name` VARCHAR( 255 ) NOT NULL ,
    `user_email` VARCHAR( 255 ) NOT NULL ,
    `user_phone` VARCHAR( 255 ) NOT NULL ,
    `user_age` INT NOT NULL ,
    `join_date` DATETIME NOT NULL ,
    PRIMARY KEY ( `user_id` )

// Include the class

 Instantiate the class, passing in the name of the class you want to generate
 along with the name of the table you are creating the class for
$class = new ClassGenerator("Example","userTable");

  Add in the primary key field for this table, the fields are
  $fieldName - the name of the DB Field
  $displayName - what you want the name to be in your class
  $dataType - Optional, sets the type in the PHPDoc comments for you
  $keyField - Optional, set to true on your primary key field

  Add in all other additional fields in your table

  If you set the $dataType parameter to datetime, date, time, or timestamp it will
  create the getter method for this field slightly differently...check the output for this field.

// Generate the class!
if (!$class->generateClass())