PHP Classes
elePHPant
Icontem

File: example.sql.builder.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of JImmy Bo  >  Bobo's Simple SQL Builder Class  >  example.sql.builder.php  >  Download  
File: example.sql.builder.php
Role: Example script
Content type: text/plain
Description: Example SQL Query building with Bobo Simple SQL Query Builder Class
Class: Bobo's Simple SQL Builder Class
Compose SQL queries from parameters
Author: By
Last change:
Date: 3 years ago
Size: 1,827 bytes
 

Contents

Class file image Download
<?php
/* Version 1
 * Please leave this comment in at the top of the script if you use this script
 * in it's entirety. That is my only request. Other then that have fun.
 *
 * Bobo's Simple SQL Builder Class
 * http://www.phpclasses.org/package/7306-PHP-Simple-SQL-Query-Building-Class.html
 *
 *
 * also check out my db access class (Bobo DB) for easy database access in PHP:
 * http://www.phpclasses.org/package/5283-PHP-Simple-MySQL-database-access-wrapper.html
 *
 * I created this class to simplify queries to and from the database. Instead of a whole bunch of
 * redundant lines of code this makes your code cleaner and easier to understand.
 *
 * also check out my websites:
 * http://insidefame.com
 * http://wellerit.com
 *
 * Also if you're looking for help from me directly you can usually find me
 * slumming it on #phphelp on the undernet irc network.
 *
 *
 */

   
include_once('class.sql.builder.php');


   
$s = new sql_builder();
   

    echo
"<hr />";

   
// example 1 - update //
   
$s->update->table('mytable');
   
$s->update->set("myval", "'5'");
   
$s->update->set("myval2", "'25'");
   
$s->update->where("id=5");
   
$s->update->limit(1);
    echo
$s->update->sql();
   
    echo
"<hr />";

   
// example 2 - insert //
   
$s->insert->table('mytable');
   
$s->insert->set("myval", "'5'");
   
$s->insert->set("myval2", "'25'");
    echo
$s->insert->sql();

    echo
"<hr />";

   
// example 3 - delete //
   
$s->delete->table('mytable');
   
$s->delete->where("id=5");
    echo
$s->delete->sql();
   
    echo
"<hr />";

   
// example 4 - select //
   
$s->select->table('mytable');
   
$s->select->cols('id,name');
   
$s->select->where('id=5');
   
$s->select->limit(1);
    echo
$s->select->sql();
   
    echo
"<hr />";

   
// example 5 - select //
   
$s->select->table('mytable');
    echo
$s->select->sql();
   
?>