ISqlComposer
in
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
Return values
stringClear()
Reset all internal data
public
Clear() : void
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
Return values
ISqlComposerFromList()
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
Return values
ISqlComposerGetItems()
Get the current items/fields in SELECT
public
GetItems() : string
Return values
stringGetTable()
Get table name by index
public
GetTable([int $index = 0 ]) : string
Parameters
- $index : int = 0
Return values
stringGetTypes()
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
Return values
ISqlComposerHaving()
Set HAVING clause
public
Having(string $having) : ISqlComposer
Parameters
- $having : string
-
conditions for group by having
Tags
Return values
ISqlComposerInnerJoin()
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
Return values
ISqlComposerJoin()
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
Return values
ISqlComposerJoinItems()
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
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
Return values
ISqlComposerLowerItem()
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
Return values
ISqlComposerOrWhere()
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
Return values
ISqlComposerPaging()
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
Return values
ISqlComposerPrepare()
Build and return the SQL query string
public
Prepare() : string
Tags
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
Return values
ISqlComposerSelect()
Set the fields of the query
public
Select(string $items) : ISqlComposer
Parameters
- $items : string
-
list of db fields separated by a comma
Tags
Return values
ISqlComposerSelectList()
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
Return values
ISqlComposerSetTypes()
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
Return values
ISqlComposerWhereBetween()
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
Return values
ISqlComposerWhereIn()
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
Return values
ISqlComposerWhereNotBetween()
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
Return values
ISqlComposerWhereNotIn()
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
Return values
ISqlComposerWhereNotNull()
Add WHERE IS NOT NULL condition
public
WhereNotNull(string $column) : ISqlComposer
Parameters
- $column : string
-
column name
Tags
Return values
ISqlComposerWhereNull()
Add WHERE IS NULL condition
public
WhereNull(string $column) : ISqlComposer
Parameters
- $column : string
-
column name