1. Go to this page and download the library: Download selcukmart/sqlbuilder library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
selcukmart / sqlbuilder example snippets
$sql_generator = [
/**
* optional, for more builders on same way
*/
'id'=>123,
/**
* Select array
*/
[
'type' => 'SELECT',
'c',
'd.f',
'a' => '*',
'b' => 'sube_id,ana_yetki_id,ad AS KUL_AD,soyad AS KUL_SOYAD',
'bx' => [
'branch_id',
'auth_id',
'name AS USER_NAME',
'surname AS USER_SURNAME',
],
'c' => 'name PAYMENT_OPTION',
'd' => 'name AS CARGO_FIRM',
[
[
'type' => 'SELECT',
'b.*',
[
[
'type' => 'SELECT',
'b.*'
],
[
'type' => 'FROM',
'b'
],
[
/**
* AS is reserved, because of it we are using AAS
* AS = AAS
*/
'type' => 'AAS',
/**
* Default this is true
* You have to use this only sub
* Otherwise you don't need AAS
*/
'sub' => true,
'aaa'
]
],
],
[
'type' => 'FROM',
'b'
],
[
/**
* AS is reserved, because of it we are using AAS
* AS = AAS
*/
'type' => 'AAS',
'BBB'
]
],
'e' => 'id AS INVOICE_ID, x_firm_invoice_id,
trackable_job_id,
status,
proccess_status,
sent,
pdf_url,
'd.x',
'c.y',
'j'
],
[
'type' => 'FROM',
'asdfg',
'AS a'
],
[
'type' => 'INNER JOIN',
'table' => [
[
[
'type' => 'SELECT',
'b.*'
],
[
'type' => 'FROM',
'b'
]
],
'b'
],
'ON' => [
/**
* 'b' => 'id',
*/
'id',
/**
* this ise this as or this table
* but for others write the table
* or table as
*/
'a' => 'kisi_id'
],
/**
* [ 'a'=>"(tip='1' OR a='2') OR (b='3' XOR C='8') AND c='123' "]
*/
'WHERE' => [
/**
* Ön Tanımlı join içinde olduğundan 'b' olacaktır.
*/
"(tip='1' OR a='2') OR (b='3' XOR C='8') AND c='123' ",
]
],
[
'type' => 'LEFT JOIN',
'table' => [
'qwer',
'q'
],
'ON' => [
'id',
'a' => 'teslimat_adresi_id'
]
],
[
'type' => 'LEFT JOIN',
'table' => [
'asd',
'asertt'
],
'ON' => [
'id',
'a' => 'fatura_adresi_id'
]
],
[
'type' => 'LEFT JOIN',
'table' => [
'ahjghhj',
'ah'
],
'ON' => [
'id',
'q' => 'il'
],
'WHERE' => [
" kume_id='0' "
]
],
[
'type' => 'LEFT JOIN',
'table' => [
'bvnbvnvbn',
'bvn'
],
'ON' => [
'id',
'asertt' => 'il'
],
'WHERE' => [
" kume_id='0' "
]
],
[
'type' => 'WHERE',
'a' => "(tip='1' OR a='2') AND (b='3' XOR C='8') AND d.c='123' ",
//'b' => "(tip='1' OR a='2') OR (b='3' XOR C='8') AND c='123' ",
//"(tip='1' OR a='2') OR (b='3' XOR C='8') AND c='123' ",
// OR
//"(a.tip='1' OR a.a='2') OR (a.b='3' XOR a.C='8') AND a.c='123' "
],
[
'type' => 'GROUP BY',
'a' => "id, sira ",
'c' => 'x,Y,Z',
'k,val'
],
[
'type' => 'LIMIT',
10
]
];
$sql = new SQLBuilder();
$sql->build($sql_generator);
/**
* Formatted Output
*/
echo $sql->getOutputFormatted();
/**
* Highlighted False Output
*/
echo $sql->getOutputFormatted(false);
/**
* Real usage output
*/
echo $sql->getOutput();
$arr = [
'TABLE' => [
/**
* also works
* type=>'TABLE',
*/
'a',
'b'
],
'ON' => [
/**
* also works
* type=>'ON',
*/
/**
* $vtable4_as => 'id',
*/
'id',
/**
* this ise this as or this table
* but for others write the table
* or table as
*/
'c' => 'kisi_id'
],
/**
* [ $vtable_as=>"(tip='1' || a='2') || (b='3' XOR C='8') AND c='123' "]
*/
'WHERE' => [
/**
* also works
* type=>'WHERE',
*/
/**
* Ön Tanımlı join içinde olduğundan $vtable4_as olacaktır.
*/
"(tip='1' AND a='2') || (b='3' XOR C='8') AND c='123' ",
]
];
$SQLBuilder = new SQLBuilder();
$operations = new JoinOperations($arr, $SQLBuilder);
$operations->build();
echo $operations->getOutput();
$arr = [
[
'type' => 'TABLE',
'a',
'b'
],
[
'type' => 'ON',
/**
* $vtable4_as => 'id',
*/
'id',
/**
* this is this as or this table
* but for others write the table
* or table as
*/
'c' => 'kisi_id'
],
[
'type' => 'WHERE',
/**
* Ön Tanımlı join içinde olduğundan $vtable4_as olacaktır.
*/
"(tip='1' AND a='2') || (b='3' XOR C='8') AND c='123' ",
]
];
$SQLBuilder = new SQLBuilder();
$operations = new JoinOperations($arr, $SQLBuilder);
$operations->build();
echo $operations->getOutput();