class Query

Constants

BOOLEAN_AND

BOOLEAN_OR

SORT_ASCENDING

SORT_DESCENDING

RETURN_FULL_QUERY

RETURN_WHERE

Methods

__construct(string $table, array $tableSchema = [])

Query constructor.

string
__toString()

Returns a String representation (SQL Query String) - depending on the defaultStringReturn setting this may be the whole SQL or only the WHERE condition SQL

array
_getScopeOrderBy()

Internal use function to copy ScopeOrder to other Query

void
clear()

Clears all scopes and conditions

static string
escapeField(string|null $field)

Escapes the passed mysql fieldname with backticks

static string
escapeValue(string|null $value)

Escapes the passed value for using it in a mysql query

array
execute(bool $i18nMode = false)

Execute Query and return Resultset

array
getJoins()

No description

string
getOrderBySQL()

Return ORDER BY part of the query

string
getSQL()

Returns the full SQL string for this Query

array
getScopeLimit()

Return Limit

array
getScopeWhere()

Returns an array with all defined Conditions

array
getScopeWhereGroup()

Returns an array with all defined Conditions

string
getSelectSQL()

Builds the SELECT SQL

array
getSelectedFields()

No description

string
getTable()

No description

array
getWhereConditionsForField($field)

Checks if a condition for the specified field is specified NOTE: This check does not (yet) cover whereRaw() conditions with custom syntaxes

string
getWhereSQL(string|null $table = null)

Builds the WHERE Condition SQL

groupBy(string $field)

Add a group by condition to the Query

bool
hasJoins()

No description

bool
hasScopeWhere(string $scopeField)

Check if a specific whereScope has been applied to the collection

join(string $baseTable, string $baseTableField, string $joinTable, string $joinTableField, string $joinType = 'LEFT JOIN', string $conditionOperator = '=')

Add join based on simple condition.

joinAddCondition(string $baseTable, string $baseTableField, string|null $joinTable, string|int $joinTableField, string $conditionOperator = '=', string $concatToPreviousConditionOperand = Query::BOOLEAN_AND)

Adds a join condition to the previous defined join, e.g.: AND {$baseTable}.{$baseTableField} = {$joinTable}.{$joinTableField}

joinInner(string $queryField, string $joinTable, string $joinTableField)

Add basic inner join based on simple condition

joinLeft(string $queryField, string $joinTable, string $joinTableField)

Add basic inner join based on simple condition

joinsFromQuery(Query $query)

No description

$this
limit(int $length, int $offset = 0)

Set Limit on Query

none()

Always evaluates the scope to FALSE and can be used to force returning an empty collection in some filter conditions

orderBy(string $field, string $sortDirection = self::SORT_ASCENDING, string|null $fieldAlias = null)

Adds a orderBy condition to the Query

orderFromQuery(Query $query)

Applies all ORDER conditions of the passed Query object to the current query (Copy)

removeSelectField(string $field)

Removes a SELECT field from the query.

resetLimit()

No description

resetOrderBy()

Resets orderBy condition of the Query

resetSelectedFields()

Reset Select Fields

select(string $selectField, string $aliasAs = null)

Adds a SELECT field to the query

selectFromQuery(Query $query)

No description

selectFromTable(string $selectField, string $table, string $aliasAs = null)

Adds a SELECT field from a specific table to the query

selectRaw(string $selectSql, string $aliasAs = null, string|null $fieldReference = null)

Adds a custom SELECT SQL to the query

void
setDefaultStringReturn($returnType)

Sets the default return if Object is converted to a STRING

void
setOnChangeCallback(callable $callback)

Registeres a Callback which is executed if the Query is being changed

static Query
table(string $table, array $tableSchema = [])

Syntax-Helper to start a query with for a table. Use as Query::table('myTable')->where('field1','=','val');

void
triggerOnChange()

Trigger onChange event callbacks

unscope(string $what = 'all')

Unscope Function to remove specific scopes of the query

unscopeFromQuery(Query $Query)

Removes all scope conditions which are set in the passed Query object (similar to boolean subtract)

unscopeWhere(string $unscopeSpecificField = null)

Removes all Where Conditions or the Conditions for a specific field

where(string $field, string $condition, string $value = null)

Adds a custom WHERE Condition to the query

whereCondition(Condition $condition)

Adds a Condition object as condition

whereConditionGroup(ConditionGroup $conditionGroup)

Adds a Condition object as condition

whereEqual(string $field, string|array $value)

Adds a EQUAL WHERE Condition to the query

whereFromQuery(Query $query)

Applies all WHERE conditions of the passed Query object to the current query (Copy)

whereLike(string $field, string $value)

Adds a LIKE Condition to the query

whereNot(string $field, string $condition, string $value = null)

Adds a custom NEGATED WHERE Condition to the query

whereNotEqual(string $field, string|array $value)

Adds a NEGATED EQUAL WHERE Condition to the query

whereRaw($rawSQL)

Adds a RAW WHERE Condition to the query

withAutoSelects()

Use automatic field conversion of timestamp and binary fields, requires tableSchema

withDistinctSelect()

No description

Details

at line 73
__construct(string $table, array $tableSchema = [])

Query constructor.

Parameters

string $table

SQL Tablename which will be the primary Table for the Query

array $tableSchema

at line 556
string __toString()

Returns a String representation (SQL Query String) - depending on the defaultStringReturn setting this may be the whole SQL or only the WHERE condition SQL

Return Value

string

at line 600
array _getScopeOrderBy()

Internal use function to copy ScopeOrder to other Query

Return Value

array

at line 447
void clear()

Clears all scopes and conditions

Return Value

void

at line 746
static string escapeField(string|null $field)

Escapes the passed mysql fieldname with backticks

Parameters

string|null $field Fieldname

Return Value

string

Returns the escaped field name

at line 762
static string escapeValue(string|null $value)

Escapes the passed value for using it in a mysql query

Parameters

string|null $value

Value to escape

Return Value

string

Returns the escaped value

at line 1002
array execute(bool $i18nMode = false)

Execute Query and return Resultset

Parameters

bool $i18nMode

Return Value

array

at line 939
array getJoins()

No description

Return Value

array

at line 588
string getOrderBySQL()

Return ORDER BY part of the query

Return Value

string

at line 548
string getSQL()

Returns the full SQL string for this Query

Return Value

string

at line 608
array getScopeLimit()

Return Limit

Return Value

array

[(int) $start, (int) $limit]

at line 573
array getScopeWhere()

Returns an array with all defined Conditions

Return Value

array

at line 580
array getScopeWhereGroup()

Returns an array with all defined Conditions

Return Value

array

at line 665
string getSelectSQL()

Builds the SELECT SQL

Return Value

string

at line 727
array getSelectedFields()

No description

Return Value

array

at line 731
string getTable()

No description

Return Value

string

at line 620
array getWhereConditionsForField($field)

Checks if a condition for the specified field is specified NOTE: This check does not (yet) cover whereRaw() conditions with custom syntaxes

Parameters

$field

Return Value

array

at line 630
string getWhereSQL(string|null $table = null)

Builds the WHERE Condition SQL

Parameters

string|null $table

Return Value

string

at line 389
Query groupBy(string $field)

Add a group by condition to the Query

Parameters

string $field

SQL Fieldname

Return Value

Query Query

at line 935
bool hasJoins()

No description

Return Value

bool

at line 507
bool hasScopeWhere(string $scopeField)

Check if a specific whereScope has been applied to the collection

Parameters

string $scopeField

Return Value

bool

at line 864
Query join(string $baseTable, string $baseTableField, string $joinTable, string $joinTableField, string $joinType = 'LEFT JOIN', string $conditionOperator = '=')

Add join based on simple condition.

{$joinType} {$joinTable} ON ({$baseTable}.{$queryField} = {$joinTable}.{$joinTableField})

Parameters

string $baseTable
string $baseTableField
string $joinTable
string $joinTableField
string $joinType
string $conditionOperator

Return Value

Query

at line 900
Query joinAddCondition(string $baseTable, string $baseTableField, string|null $joinTable, string|int $joinTableField, string $conditionOperator = '=', string $concatToPreviousConditionOperand = Query::BOOLEAN_AND)

Adds a join condition to the previous defined join, e.g.: AND {$baseTable}.{$baseTableField} = {$joinTable}.{$joinTableField}

If no joinTable is defined (null) the $joinTableField will be treated as value: AND {$baseTable}.{$baseTableField} = '{$joinTableField}'

Parameters

string $baseTable
string $baseTableField
string|null $joinTable

If null, the joinTableField will be treated as value

string|int $joinTableField
string $conditionOperator

['=','>','<','>=','<=', '<>']

string $concatToPreviousConditionOperand

Query::BOOLEAN_AND || Query::BOOLEAN_OR

Return Value

Query

at line 835
Query joinInner(string $queryField, string $joinTable, string $joinTableField)

Add basic inner join based on simple condition

Parameters

string $queryField
string $joinTable
string $joinTableField

Return Value

Query

at line 848
Query joinLeft(string $queryField, string $joinTable, string $joinTableField)

Add basic inner join based on simple condition

Parameters

string $queryField
string $joinTable
string $joinTableField

Return Value

Query

at line 943
Query joinsFromQuery(Query $query)

No description

Parameters

Query $query

Return Value

Query

at line 364
$this limit(int $length, int $offset = 0)

Set Limit on Query

Parameters

int $length
int $offset

Return Value

$this

at line 376
Query none()

Always evaluates the scope to FALSE and can be used to force returning an empty collection in some filter conditions

Return Value

Query Query

at line 425
Query orderBy(string $field, string $sortDirection = self::SORT_ASCENDING, string|null $fieldAlias = null)

Adds a orderBy condition to the Query

Parameters

string $field

SQL Fieldname

string $sortDirection

Sort Direction [Query::SORT_DESCENDING | Query::SORT_ASCENDING)

string|null $fieldAlias

Specifically use given alias

Return Value

Query $this

at line 350
Query orderFromQuery(Query $query)

Applies all ORDER conditions of the passed Query object to the current query (Copy)

Parameters

Query $query

Query object with specified WHERE conditions

Return Value

Query $this

at line 151
Query removeSelectField(string $field)

Removes a SELECT field from the query.

Parameters

string $field

Return Value

Query

at line 410
Query resetLimit()

No description

Return Value

Query

at line 401
Query resetOrderBy()

Resets orderBy condition of the Query

Return Value

Query $this

at line 206
Query resetSelectedFields()

Reset Select Fields

Return Value

Query

at line 134
Query select(string $selectField, string $aliasAs = null)

Adds a SELECT field to the query

Parameters

string $selectField

SQL Field to select

string $aliasAs

Return Value

Query

at line 322
Query selectFromQuery(Query $query)

No description

Parameters

Query $query

Return Value

Query

at line 167
Query selectFromTable(string $selectField, string $table, string $aliasAs = null)

Adds a SELECT field from a specific table to the query

Parameters

string $selectField

SQL Field to select

string $table

SQL Table present in this query (e.g. from join)

string $aliasAs

Return Value

Query

at line 188
Query selectRaw(string $selectSql, string $aliasAs = null, string|null $fieldReference = null)

Adds a custom SELECT SQL to the query

Parameters

string $selectSql
string $aliasAs
string|null $fieldReference

If given, ordering will use this field instead of the calculated alias

Return Value

Query

at line 105
void setDefaultStringReturn($returnType)

Sets the default return if Object is converted to a STRING

Parameters

$returnType

[Query::RETURN_WHERE | Query::RETURN_FULL_QUERY]

Return Value

void

at line 85
void setOnChangeCallback(callable $callback)

Registeres a Callback which is executed if the Query is being changed

Parameters

callable $callback

Callback Function

Return Value

void

at line 122
static Query table(string $table, array $tableSchema = [])

Syntax-Helper to start a query with for a table. Use as Query::table('myTable')->where('field1','=','val');

Parameters

string $table

SQL Tablename

array $tableSchema

Return Value

Query

at line 93
void triggerOnChange()

Trigger onChange event callbacks

Return Value

void

at line 464
Query unscope(string $what = 'all')

Unscope Function to remove specific scopes of the query

Parameters

string $what

Return Value

Query

at line 524
Query unscopeFromQuery(Query $Query)

Removes all scope conditions which are set in the passed Query object (similar to boolean subtract)

Parameters

Query $Query

Return Value

Query

at line 489
Query unscopeWhere(string $unscopeSpecificField = null)

Removes all Where Conditions or the Conditions for a specific field

Parameters

string $unscopeSpecificField

Return Value

Query

at line 229
Query where(string $field, string $condition, string $value = null)

Adds a custom WHERE Condition to the query

Parameters

string $field

SQL Fieldname

string $condition

SQL Condition Operatior ('=', '>', '<',...)

string $value

Comparison Value if required for operator

Return Value

Query $this

at line 303
Query whereCondition(Condition $condition)

Adds a Condition object as condition

Parameters

Condition $condition

Condition object

Return Value

Query

at line 316
Query whereConditionGroup(ConditionGroup $conditionGroup)

Adds a Condition object as condition

Parameters

ConditionGroup $conditionGroup

Return Value

Query

at line 254
Query whereEqual(string $field, string|array $value)

Adds a EQUAL WHERE Condition to the query

Parameters

string $field

SQL Fieldname

string|array $value

Expected value

Return Value

Query $this

at line 332
Query whereFromQuery(Query $query)

Applies all WHERE conditions of the passed Query object to the current query (Copy)

Parameters

Query $query

Query object with specified WHERE conditions

Return Value

Query $this

at line 278
Query whereLike(string $field, string $value)

Adds a LIKE Condition to the query

Parameters

string $field

SQL Fieldname

string $value

Expected value

Return Value

Query $this

at line 242
Query whereNot(string $field, string $condition, string $value = null)

Adds a custom NEGATED WHERE Condition to the query

Parameters

string $field

SQL Fieldname

string $condition

SQL Condition Operatior ('=', '>', '<',...)

string $value

Comparison Value if required for operator

Return Value

Query $this

at line 266
Query whereNotEqual(string $field, string|array $value)

Adds a NEGATED EQUAL WHERE Condition to the query

Parameters

string $field

SQL Fieldname

string|array $value

Expected value

Return Value

Query $this

at line 292
Query whereRaw($rawSQL)

Adds a RAW WHERE Condition to the query

Parameters

$rawSQL

Return Value

Query $this

at line 783
Query withAutoSelects()

Use automatic field conversion of timestamp and binary fields, requires tableSchema

Return Value

Query

at line 816
Query withDistinctSelect()

No description

Return Value

Query