PHP Classes
elePHPant
Icontem

sql_Generator: Class used to ease generation of SQL queries

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2003-07-29 (12 years ago) RSS 2.0 feedNot enough user ratingsTotal: 875 All time: 3,765 This week: 1,244Up
Version License Categories  
sql_generator 1.0GNU Lesser Genera...Databases
Description Author  

This class is meant to make it easier to generate SQL queries for inserting or updating records in a database table.

Just specify the required fields, and then call the class functions to retrieve the SQL statement to perform an insert or update query.

Picture of Carsten Gehling
Name: Carsten Gehling <contact>
Classes: 1 package by
Country: Denmark Denmark
Age: 43
All time rank: 233816 in Denmark Denmark
Week rank: 1498 Up7 in Denmark Denmark Up

Details provided by the author  
Project: sql_Generator
Version: 0.9
Author: Carsten Gehling (carsten@sarum.dk)
Date: 2003-07-29

About this file
----------------
This is the documentation for sql_Generator. The example files pretty much
explains everything however.

If you have any questions regarding the use of sql_Generator or suggestions
for this README file, please contact me at carsten@sarum.dk. I will
get back to you as soon as possible.

TODO:
------
This class is made specifically for MySQL. I would like to make it functional
for other DBMS including their little quirks.

sql_Generator
---------------
The class sql_Generator is used to automatically generate either insert or
update sql statements based on the same set of fields.

For a complete example, please refer to the files:
    example1.php
    example2.php

Here follows a description of the public interface:

function sql_Generator($tablename = "")
-----------------------------------------
This is constructor for the object.

Parameters:
    tablename: The name of the table that is to be used in the sql statement


function create($tablename)
-----------------------------
Resets the class to make a new sql statement on another table

Parameters:
    tablename: The name of the table that is to be used in the sql statement


function addField($key, $value, $type = "string")
---------------------------------------------------
This function should be called for every field that you want
to insert/update in the record.

Parameters:
    key:   The name of the field
    value: The new value of the field
    type:  How should the field be represented in the sql statement?
           Values can be "string", "number" or "function"; default is "string".
           "string" can be used in most cases, since MySQL accepts apostrofs around
           any value except function calls.


function makeInsert()
-----------------------
This function returns a sql statement for inserting records in the table.
Returns "" if the class has not been supplied with a tablename and/or fields.

Parameters:
    None


function makeUpdateKey($key, $value, $type = "string")
--------------------------------------------------------
This function returns a sql statement for updating records in the table
given a field description to identify the record.
Returns "" if the class has not been supplied with a tablename and/or fields.

Parameters:
    key:   The name of the field
    value: The value to use for identifying the record.
    type:  How should the field be represented in the sql statement?
           Values can be "string", "number" or "function"; default is "string".
           "string" can be used in most cases, since MySQL accepts apostrofs around
           any value except function calls.


function makeUpdateKey($key, $value, $type = "string")
--------------------------------------------------------
This function returns a sql statement for updating records in the table
given a where expression.
Returns "" if the class has not been supplied with a tablename and/or fields.

Parameters:
    whereexpr: An expression like "age < 21". The keyword "where" is automatically
               added.
  Files folder image Files  
File Role Description
Plain text file class_sql_generator.php Class Main class file
Accessible without login Plain text file COPYING Lic. LGPL License
Accessible without login Plain text file example1.php Example Example on how to use the class
Accessible without login Plain text file example2.php Example Example on how to use the class
Accessible without login Plain text file LICENSE Lic. Personal license information
Accessible without login Plain text file README Doc. Class documentation

 Version Control Unique User Downloads Download Rankings  
 0%Total:875All time:3,765
 This week:0This week:1,244Up