Login   Register  
PHP Classes
elePHPant
Icontem

File: use.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of J.B.  >  MyQuery  >  use.php  >  Download  
File: use.php
Role: Example script
Content type: text/plain
Description: Sample use
Class: MyQuery
MySQL query generator
Author: By
Last change:
Date: 2003-03-18 14:01
Size: 2,104 bytes
 

Contents

Class file image Download
<?php
/*    
    Sample use
*/

include('myquery.class.php');

$q = new MyQuery();
$q->setAction('SELECT');
$q->setTable('article_table');
$q->setCondition("status='published'");
$q->setOrder('time','DESC');
echo 
$q->getQuery().'<br />';
    
// SELECT * FROM article_table WHERE status='published'

$q->setCondition("author='John'");
$q->setField('id');
$q->setField('intro');
echo 
$q->getQuery().'<br />';
    
// SELECT id, intro FROM article_table
    // WHERE status='published' AND author='John'

$q->initVars();    
$q->setAction('INSERT');
$q->setTable('article_table');
$q->setInsert('id',''); 
    
// we'll use auto_incement - no need for specific id
$q->setInsert('author','Peter');
$q->setInsert('title','The great article');
$q->setInsert('intro','This is an intro for the great article.');
$q->setInsert('content','This is the content of the great article.');
$q->setInsert('time',time());
echo 
$q->getQuery().'<br />';
    
// INSERT INTO article_table (id, author, title, intro, content, time)
    // VALUES ('', 'Peter', 'The great article', 'This is an intro for the great article.',
    // 'This is the content of the great article.', '1047987853')
    
$q->initVars();
$q->setAction('UPDATE');
$q->setTable('rakstu_tabula');
$q->setUpdate('autors','Juris Jura d&#275;ls');
$q->setCondition("autors='Juris'");
$q->setCondition("status='publicets'");
echo 
$q->getQuery().'<br />';
    
// UPDATE rakstu_tabula SET autors='Juris Jura d&#275;ls'
    // WHERE autors='Juris' AND status='publicets'

   
$q->initVars();
$q->setAction('DELETE');
$q->setTable('rakstu_tabula');
$q->setCondition("status='novecojis'");
echo 
$q->getQuery().'<br />';
    
// DELETE FROM rakstu_tabula WHERE status='novecojis'

/*
    All these were simple queries on one table, here is
    another one, working on two tables.
*/  

$q = new MyQuery();
$q->setAction('SELECT');
$q->setTable('articles','a');
$q->setTable('topics','t');
$q->setTable('writers','w');
$q->setCondition("a.aid=t.aid");
$q->setCondition("a.aid=w.aid");
$q->getQuery();
?>