PHP Classes

File: test/php/test3.php

Recommend this page to a friend!
  Classes of Nikos M.   Dialect PHP SQL Query Builder   test/php/test3.php   Download  
File: test/php/test3.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Dialect PHP SQL Query Builder
Build SQL queries from templates
Author: By
Last change: v.1.4.0 contd

* support default values in sql_function, sql_type
* more standard and versatile sql types supported
* add JSON sql type
Date: 1 year ago
Size: 1,585 bytes
 

Contents

Class file image Download
<?php
include "../../src/php/Dialect.php";
function
echo_($s = '')
{
    echo
$s . PHP_EOL;
}

echo_('Dialect.VERSION = ' . Dialect::VERSION);
echo_();

$dialect = new Dialect('mysql');

$query = $dialect
       
->clear()
        ->
Select()
        ->
Order($dialect->sql_function('random'))
        ->
From('table AS main')
        ->
sql()
    ;

$quoted_id = $dialect->quote_name('trick`ier');
$quoted_lit = $dialect->quote('trick\'\\ier');

$query2 = $dialect->clear()->Select($quoted_id.' AS trickier, "trick\'y" AS tricky')->From('table')->sql();

$query3 = $dialect
       
->clear()
        ->
Select()
        ->
From('table')
        ->
Where(array('id'=>array('in'=>$dialect->subquery()->Select('id')->From('anothertable')->sql(),'type'=>'raw')))
        ->
sql()
    ;
$query4 = implode('',array(
       
$dialect->clear()->Insert('table',array('col1','col2'))->sql(),
       
$dialect->clear()->Select('col1,col2')->From('anothertable')->Where(array('id'=>1))->sql()
    ));

$query5 = $dialect->clear()->Select('anothertable.col1,anothertable.col2,dynamictable.*')->From(array('anothertable','('.
           
$dialect->subquery()
            ->
Select($quoted_id)
            ->
From('table')
            ->
Where(array('col4'=>array('like'=>'foo')))
            ->
sql().
       
') AS dynamictable'))->Where(array('id'=>1))->sql();

echo_( 'SQL dialect = ' . $dialect->type );
echo_( );
echo_( $query );
echo_( );
echo_( $quoted_id );
echo_( );
echo_( $quoted_lit );
echo_( );
echo_( $query2 );
echo_( );
echo_( $query3 );
echo_( );
echo_( $query4 );
echo_( );
echo_( $query5 );