Location: PHPKode > scripts > sql_Generator class > sql_generator-class/example2.php
<?php
/********************************************************************
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)
) TYPE=MyISAM;
********************************************************************/

///////////////////////////////////////////////
// Including the sql_Generator class
require_once("class_sql_generator.php");

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

///////////////////////////////////////////////
// Add common fields
$sqlgen->addField("name", "Anonymous");
$sqlgen->addField("email", "hide@address.com");

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

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

echo $sql;

$con = mysql_connect("localhost", "root", "pollew32");
mysql_select_db("test");
mysql_query($sql) or die(mysql_error());
mysql_close();
?>
Return current item: sql_Generator class