PHP Classes

File: test/php/test2.php

Recommend this page to a friend!
  Classes of Nikos M.  >  Dialect PHP SQL Query Builder  >  test/php/test2.php  >  Download  
File: test/php/test2.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: 2 months ago
Size: 1,652 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('sqlserver');

echo_($dialect->clear()->Create('new_table', array(
   
'ifnotexists' => true,
   
'columns' => array(
        array(
'column'=>'id', 'type'=>$dialect->sql_type('bigint',[20]), 'isnotnull'=>1, 'auto_increment'=>1),
        array(
'column'=>'name', 'type'=>$dialect->sql_type('varchar',[100]), 'isnotnull'=>1, 'default_value'=>"''"),
        array(
'column'=>'categoryid', 'type'=>$dialect->sql_type('bigint',[20]), 'isnotnull'=>1, 'default_value'=>0),
        array(
'column'=>'companyid', 'type'=>$dialect->sql_type('bigint',[20]), 'isnotnull'=>1, 'default_value'=>0),
        array(
'column'=>'fields', 'type'=>$dialect->sql_type('text'), 'isnotnull'=>1, 'default_value'=>"''"),
        array(
'column'=>'start', 'type'=>$dialect->sql_type('datetime'), 'isnotnull'=>1, 'default_value'=>"'0000-00-00 00:00:00'"),
        array(
'column'=>'end', 'type'=>$dialect->sql_type('datetime'), 'isnotnull'=>1, 'default_value'=>"'0000-00-00 00:00:00'"),
        array(
'column'=>'status', 'type'=>$dialect->sql_type('smallint',[8]), 'isnotnull'=>1, 'default_value'=>0),
        array(
'column'=>'extra', 'type'=>$dialect->sql_type('text'), 'isnotnull'=>1, 'default_value'=>"''")
    ),
   
'table'=> array(
        array(
'collation'=>'utf8_general_ci')
    )
))->
sql());

echo_();

echo_($dialect->clear()->Create('new_view', array(
   
'view'=> true,
   
'ifnotexists'=> true,
   
'columns'=> array('id', 'name'),
   
'query'=> 'SELECT id, name FROM another_table'
))->sql());