WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Simple class to create insert and update statements. Independent of the access to the database. Makes handling complex inserts easier - especially when the table structure is liable to change.
Categories : Databases, PHP Classes, PHP Update Picture
Sarah King
Date : Mar 15th 2002
Grade : 1 of 5 (graded 1 times)
Viewed : 11426
File : cl_insert.php
Images : No Images for this code example.
Search : More code by Sarah King
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php
////////////////////////////////////////////////////////////
// CreateSQL 0.1
// class for creating SQL statements independant of the database
// not always appropriate to create the SQL within the db class
// Makes complex inserts easier to manage - visually easier editing
//
// Sarah King
// sarah@pcpropertymanager.com
// http://www.pcpropertymanager.com
//
//
//         $sql = new CreateSQL("mytable","mytableid");
//         $sql->set_fields( array( "name" => $username,
//         "email" => $email,
//         "phone" => $tel,
//         "fax" => $fax,
//         "address" => $address,
//         "postcode" => $postcode,
//         "country" => $country,
//         ));                 
//
// then use database class to run the query
// $db->query($sql->getUpdateSQL());
//
////////////////////////////////////////////////////////////


if(!defined("__CreateSQL__")) {
define("__CreateSQL__",1);

class CreateSQL
{
/**************************************************************************
********
Create Insert and update clauses based on data passed.
***************************************************************************
*******/

        var $aFields = array();
        var $tablename;
        var $primarykey;
        var $primarykeyvalue;
        var $whereClause = "";

        function CreateSQL($tablename, $primarykey, $primarykeyvalue = "NULL")        //
constructor
        {
                $this->tablename = $tablename;
                $this->primarykey = $primarykey;
                $this->primarykeyvalue = $primarykeyvalue;
        }
        
function set_fields($fieldname, $fieldvalue = "") {
if (!is_array($fieldname)) {
if ($fieldvalue == "") {
$fieldvalue = "NULL";
}
$this->aFields[$fieldname] = $fieldvalue;
} else {
reset($fieldname);
while(list($f, $v) = each($fieldname)) {
$this->aFields[$f] = $v;
}
}
}

function setPrimaryKey($keyval){
$this->primarykeyvalue = $keyval;
} //setPrimaryKeyVal

function setWhere($where){
$this->whereClause .= $where;
}

        function getInsertSQL()
        {
$output = "insert into " . $this->tablename . " (";
         $fieldnames = "";
         $fieldvals = "";

reset($this->aFields);
         while(list($f, $v) = each($this->aFields)) {
$fieldnames .= $f . ", ";
                 $fieldvals .= "'" . addslashes($v) . "', ";
}
         $fieldnames = substr($fieldnames, 0, -2);
         $fieldvals = substr($fieldvals, 0, -2);

         $output .= $fieldnames . ") values (" .$fieldvals . ")";
         return $output;

        }// getInsertSQL

        function getUpdateSQL()
        {
$output = "update " . $this->tablename . " set ";
         $vars = "";
reset($this->aFields);
         while(list($f, $v) = each($this->aFields)) {
$vars .= "$f = '" . addslashes($v) . "', ";
}
         $output .= substr($vars, 0, -2);

         if ($this->primarykeyvalue != "NULL"){
         //MySQL doesn't object to quotes around numbers
$output .= " where " . $this->primarykey . " = '" . $this-
>primarykeyvalue . "'";
                 $bitstr = " and ";
         }
         else $bitstr = " where ";
         if (!empty($this->whereClause)) $output .= $bitstr . $this->whereClause;

         return $output;

        }// getUpdateSQL

} // class CreateSQL
}// end of definition statement
?>



MySQL Handler
Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes
Simple Mini Poll class library (SimPoll)
Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs
Use this class to connect your database transparently...
Categories : PHP Classes, Databases, PHP
This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases
The Ajax Tree view class fetches data from a db for the requested parent category id. The data is then stored in an array and converted into JSON (Javascript Object Notation) format. This format is then used by JavaScript for populating tree view.
Categories : PHP, PHP Classes, Java Script, AJAX, Databases
[PHP5] aDB PDO LIKE Database Abstraction. Switch easily from one db server to another, strong errors management, manage transactions, queries preparation and more.
Categories : PHP, PHP Classes, Databases, MS SQL Server, MySQL
Database and Recordset classes fo SyBASE Usage is obvious.
Categories : Sybase, Databases, PHP Classes, PHP
TableMaint: class to help in the updating of data stored in database tables
Categories : PHP, PHP Classes, Databases
Simple usersOnline class - keep track of how many users are online on your site
Categories : PHP, PHP Classes, Databases, MySQL
PHP5 SQLite Abstraction class
Categories : PHP, PHP Classes, SQLite, Databases
Specify your connection settings and create a link to a MySQL database.
Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides
PostGreSQL and MySQL 2 in 1 db Manager
Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL
DbObject - A PHP wrapper for working with various databases
Categories : Databases, PHP, PHP Classes
Password reminder
Categories : PHP, PHP Classes, Databases, MySQL, Mail
Online Automatic Class Generator for MySQL Tables
Categories : PHP, PHP Classes, Classes and Objects, Databases, MySQL