PHP Classes

File: example2.php

Recommend this page to a friend!
  Classes of Carsten Gehling  >  sql_Generator  >  example2.php  >  Download  
File: example2.php
Role: Example script
Content type: text/plain
Description: Example on how to use the class
Class: sql_Generator
Class used to ease generation of SQL queries
Author: By
Last change:
Date: 19 years ago
Size: 1,602 bytes


Class file image Download
Example file
This example shows how to use the sql_Generator class

The example shows the use of the function makeUpdate()
It updates the name and e-mail field to anonymous if the customer is
under 18 years.

The example is based on the following MySQL table:

CREATE TABLE customer (
  cust_id int(10) unsigned NOT NULL auto_increment,
  name varchar(60) NOT NULL default '',
  email varchar(60) NOT NULL default '',
  age tinyint(3) unsigned NOT NULL default '0',
  date_created datetime NOT NULL default '0000-00-00 00:00:00',
  date_modified datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY (cust_id)

// Including the sql_Generator class

// Create new generator class
$sqlgen = new sql_Generator("customer");

// Add common fields
$sqlgen->addField("name", "Anonymous");
$sqlgen->addField("email", "anonymous@user");

// The field "date_modified" should be updated using a MySQL function
$sqlgen->addField("date_modified", "now()", "function");

$sql = $sqlgen->makeUpdate("age < 18");


$con = mysql_connect("localhost", "root", "pollew32");
mysql_query($sql) or die(mysql_error());

For more information send a message to info at phpclasses dot org.