Documentation

ISqlComposer

Interface for SQL query composers Defines the contract for building SQL queries across different DBMS

Table of Contents

Methods

__toString()  : string
Convert the SQL composer to a string (the SQL query)
AndWhere()  : CSqlComposerBase
Add "AND" WHERE condition
As()  : string
Create AS alias for SELECT item
Clear()  : void
Reset all internal data
From()  : ISqlComposer
Set the main table for the query
FromList()  : ISqlComposer
Set multiple tables for the query
GetItems()  : string
Get the current items/fields in SELECT
GetTable()  : string
Get table name by index
GetTypes()  : array<string|int, mixed>
Get types for prepared statement placeholders
GetValues()  : array<string|int, mixed>
Get values for prepared statement placeholders
GroupBy()  : ISqlComposer
Set GROUP BY clause
Having()  : ISqlComposer
Set HAVING clause
InnerJoin()  : ISqlComposer
Add INNER JOIN clause
Join()  : ISqlComposer
Add JOIN clause
JoinItems()  : string
DBMS-specific: Concatenate multiple items
LeftJoin()  : ISqlComposer
Add LEFT JOIN clause
LowerItem()  : string
DBMS-specific: Convert item to lowercase
OrderBy()  : ISqlComposer
Set ORDER BY clause
OrWhere()  : ISqlComposer
Add OR WHERE condition
Paging()  : ISqlComposer
Set pagination parameters
Prepare()  : string
Build and return the SQL query string
RightJoin()  : ISqlComposer
Add RIGHT JOIN clause
Select()  : ISqlComposer
Set the fields of the query
SelectList()  : ISqlComposer
Set the fields of the query from array
SetTypes()  : void
Set types for ? operator in the WHERE conditions
SetValues()  : void
Set values for ? operator in the WHERE conditions
UpperItem()  : string
DBMS-specific: Convert item to uppercase
Where()  : ISqlComposer
Add WHERE conditions
WhereBetween()  : ISqlComposer
Add WHERE BETWEEN condition
WhereIn()  : ISqlComposer
Add WHERE IN condition
WhereNotBetween()  : ISqlComposer
Add WHERE NOT BETWEEN condition
WhereNotIn()  : ISqlComposer
Add WHERE NOT IN condition
WhereNotNull()  : ISqlComposer
Add WHERE IS NOT NULL condition
WhereNull()  : ISqlComposer
Add WHERE IS NULL condition

Methods

__toString()

Convert the SQL composer to a string (the SQL query)

public __toString() : string
Return values
string —

The composed SQL query

AndWhere()

Add "AND" WHERE condition

public AndWhere(string $conditions[, array<string|int, mixed>|int|string $values = [] ][, array<string|int, mixed>|int|string $types = [] ]) : CSqlComposerBase
Parameters
$conditions : string

WHERE conditions

$values : array<string|int, mixed>|int|string = []

list of values in WHERE conditions (replaced by '?')

$types : array<string|int, mixed>|int|string = []

list of types mapped one to one with values (it depends on used DBMS)

Return values
CSqlComposerBase —

this object

As()

Create AS alias for SELECT item

public As(string $item) : string
Parameters
$item : string
Tags
throws
InvalidArgumentException

if item is invalid

Return values
string

From()

Set the main table for the query

public From(string $table[, string|null $as = null ]) : ISqlComposer
Parameters
$table : string

name of table

$as : string|null = null

alias table name

Tags
throws
InvalidArgumentException

if table name is invalid

Return values
ISqlComposer

FromList()

Set multiple tables for the query

public FromList(array<string|int, mixed> $tables) : ISqlComposer
Parameters
$tables : array<string|int, mixed>

list of table names

Tags
throws
InvalidArgumentException

if tables array is invalid

Return values
ISqlComposer

GetItems()

Get the current items/fields in SELECT

public GetItems() : string
Return values
string

GetTable()

Get table name by index

public GetTable([int $index = 0 ]) : string
Parameters
$index : int = 0
Return values
string

GetTypes()

Get types for prepared statement placeholders

public GetTypes() : array<string|int, mixed>
Return values
array<string|int, mixed>

GetValues()

Get values for prepared statement placeholders

public GetValues() : array<string|int, mixed>
Return values
array<string|int, mixed>

GroupBy()

Set GROUP BY clause

public GroupBy(string $group_by) : ISqlComposer
Parameters
$group_by : string

list of field names to group by

Tags
throws
InvalidArgumentException

if group by clause is invalid

Return values
ISqlComposer

Having()

Set HAVING clause

public Having(string $having) : ISqlComposer
Parameters
$having : string

conditions for group by having

Tags
throws
InvalidArgumentException

if having clause is invalid

Return values
ISqlComposer

InnerJoin()

Add INNER JOIN clause

public InnerJoin(string $table, string $on_condition[, string|null $as = null ]) : ISqlComposer
Parameters
$table : string

name of table

$on_condition : string

condition for crossing with a starting table

$as : string|null = null

alias table name

Tags
throws
InvalidArgumentException

if parameters are invalid

Return values
ISqlComposer

Join()

Add JOIN clause

public Join(string $table, string $on_condition[, string|null $as = null ]) : ISqlComposer
Parameters
$table : string

name of table

$on_condition : string

condition for crossing with a starting table

$as : string|null = null

alias table name

Tags
throws
InvalidArgumentException

if parameters are invalid

Return values
ISqlComposer

JoinItems()

DBMS-specific: Concatenate multiple items

public JoinItems(array<string|int, mixed> $items, string $new_name) : string
Parameters
$items : array<string|int, mixed>

list of items to concatenate

$new_name : string

unused parameter for backward compatibility

Tags
throws
InvalidArgumentException

if items array is invalid

Return values
string —

SQL concatenation expression

LeftJoin()

Add LEFT JOIN clause

public LeftJoin(string $table, string $on_condition[, string|null $as = null ]) : ISqlComposer
Parameters
$table : string

name of table

$on_condition : string

condition for crossing with a starting table

$as : string|null = null

alias table name

Tags
throws
InvalidArgumentException

if parameters are invalid

Return values
ISqlComposer

LowerItem()

DBMS-specific: Convert item to lowercase

public LowerItem(string $item[, string $new_name = '' ]) : string
Parameters
$item : string
$new_name : string = ''
Return values
string —

SQL LOWER expression

OrderBy()

Set ORDER BY clause

public OrderBy(array<string|int, mixed> $order_by) : ISqlComposer
Parameters
$order_by : array<string|int, mixed>

list of field names to order by

Tags
throws
InvalidArgumentException

if order by array is invalid

Return values
ISqlComposer

OrWhere()

Add OR WHERE condition

public OrWhere(string $conditions[, array<string|int, mixed>|int|string $values = [] ][, array<string|int, mixed>|int|string $types = [] ]) : ISqlComposer
Parameters
$conditions : string

WHERE conditions

$values : array<string|int, mixed>|int|string = []

list of values in WHERE conditions

$types : array<string|int, mixed>|int|string = []

list of types mapped one to one with values

Tags
throws
InvalidArgumentException

if conditions are malformed

Return values
ISqlComposer

Paging()

Set pagination parameters

public Paging(int $page[, int $elements_per_page = 20 ]) : ISqlComposer
Parameters
$page : int

page to read (starting from 1)

$elements_per_page : int = 20

maximum total of elements that make up a page

Tags
throws
InvalidArgumentException

if parameters are invalid

Return values
ISqlComposer

Prepare()

Build and return the SQL query string

public Prepare() : string
Tags
throws
RuntimeException

if query cannot be built

Return values
string —

the composed SQL query

RightJoin()

Add RIGHT JOIN clause

public RightJoin(string $table, string $on_condition[, string|null $as = null ]) : ISqlComposer
Parameters
$table : string

name of table

$on_condition : string

condition for crossing with a starting table

$as : string|null = null

alias table name

Tags
throws
InvalidArgumentException

if parameters are invalid

Return values
ISqlComposer

Select()

Set the fields of the query

public Select(string $items) : ISqlComposer
Parameters
$items : string

list of db fields separated by a comma

Tags
throws
InvalidArgumentException

if items format is invalid

Return values
ISqlComposer

SelectList()

Set the fields of the query from array

public SelectList(array<string|int, mixed> $items) : ISqlComposer
Parameters
$items : array<string|int, mixed>

array contains the list of db fields

Tags
throws
InvalidArgumentException

if array is empty or contains invalid items

Return values
ISqlComposer

SetTypes()

Set types for ? operator in the WHERE conditions

public SetTypes(array<string|int, mixed> $types) : void
Parameters
$types : array<string|int, mixed>

list of types for ? operator in the WHERE conditions

SetValues()

Set values for ? operator in the WHERE conditions

public SetValues(array<string|int, mixed> $values) : void
Parameters
$values : array<string|int, mixed>

list of values for ? operator in the WHERE conditions

UpperItem()

DBMS-specific: Convert item to uppercase

public UpperItem(string $item[, string $new_name = '' ]) : string
Parameters
$item : string
$new_name : string = ''
Return values
string —

SQL UPPER expression

Where()

Add WHERE conditions

public Where(string $conditions[, array<string|int, mixed>|int|string $values = [] ][, array<string|int, mixed>|int|string $types = [] ]) : ISqlComposer
Parameters
$conditions : string

WHERE conditions

$values : array<string|int, mixed>|int|string = []

list of values in WHERE conditions (replaced by '?')

$types : array<string|int, mixed>|int|string = []

list of types mapped one to one with values

Tags
throws
InvalidArgumentException

if conditions are malformed

Return values
ISqlComposer

WhereBetween()

Add WHERE BETWEEN condition

public WhereBetween(string $column, mixed $min, mixed $max[, string $type = '' ]) : ISqlComposer
Parameters
$column : string

column name

$min : mixed

minimum value

$max : mixed

maximum value

$type : string = ''

type of values

Tags
throws
InvalidArgumentException

if parameters are invalid

Return values
ISqlComposer

WhereIn()

Add WHERE IN condition

public WhereIn(string $column, array<string|int, mixed> $values[, string $type = '' ]) : ISqlComposer
Parameters
$column : string

column name

$values : array<string|int, mixed>

list of values for IN clause

$type : string = ''

type of values

Tags
throws
InvalidArgumentException

if column or values are invalid

Return values
ISqlComposer

WhereNotBetween()

Add WHERE NOT BETWEEN condition

public WhereNotBetween(string $column, mixed $min, mixed $max[, string $type = '' ]) : ISqlComposer
Parameters
$column : string

column name

$min : mixed

minimum value

$max : mixed

maximum value

$type : string = ''

type of values

Tags
throws
InvalidArgumentException

if parameters are invalid

Return values
ISqlComposer

WhereNotIn()

Add WHERE NOT IN condition

public WhereNotIn(string $column, array<string|int, mixed> $values[, string $type = '' ]) : ISqlComposer
Parameters
$column : string

column name

$values : array<string|int, mixed>

list of values for NOT IN clause

$type : string = ''

type of values

Tags
throws
InvalidArgumentException

if column or values are invalid

Return values
ISqlComposer

WhereNotNull()

Add WHERE IS NOT NULL condition

public WhereNotNull(string $column) : ISqlComposer
Parameters
$column : string

column name

Tags
throws
InvalidArgumentException

if column is invalid

Return values
ISqlComposer

WhereNull()

Add WHERE IS NULL condition

public WhereNull(string $column) : ISqlComposer
Parameters
$column : string

column name

Tags
throws
InvalidArgumentException

if column is invalid

Return values
ISqlComposer

        
On this page

Search results