PHP Classes

File: example.mquery.php

Recommend this page to a friend!
  Classes of Madis   MySQL Query Generator   example.mquery.php   Download  
File: example.mquery.php
Role: Example script
Content type: text/plain
Description: Example script
Class: MySQL Query Generator
Compose MySQL queries dynamically
Author: By
Last change: added example: using setkey() with array
Date: 19 years ago
Size: 1,274 bytes


Class file image Download


// generate query for table people,
// use conditions for username and haircolor
// order by realname

$q=new mquery('people','username like "a%",haircolor="blue"','realname');

// generate a delete query based on defined conditions
echo "1: ".$q->genquery('delete')."<br>\n";

// 1: DELETE FROM people WHERE ((username like "a%") AND (haircolor="blue"))

// drop haircolor condition

// add new evaluations

// generate an insert query
echo "2: ".$q->genquery('insert')."<br>\n";

// 2: INSERT INTO people SET shoesize='36', haircolor='yellow', eyecolor='blue'

// add new haircolor condition

// drop eyecolor evaluation

// generate an update query
echo "3: ".$q->genquery('update')."<br>\n";

// 3: UPDATE people SET shoesize='36', haircolor='yellow' WHERE ((username like "a%") AND (haircolor=10))

// generate a select query
echo "4: ".$q->genquery('select')."<br>\n";

// 4: SELECT shoesize, haircolor FROM people WHERE ((username like "a%") AND (haircolor=10)) ORDER BY realname