File: test/test3.php

Recommend this page to a friend!
  Classes of Nikos M.  >  Dialect PHP SQL Query Builder  >  test/test3.php  >  Download  
File: test/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: Update of test/test3.php
Date: 3 months ago
Size: 1,515 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
       
->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->Select($quoted_id.' AS trickier, "trick\'y" AS tricky')->From('table')->sql();

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

$query5 = $dialect->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 );


For more information send a message to info at phpclasses dot org.