class Query

Constants

BOOLEAN_AND

BOOLEAN_OR

SORT_ASCENDING

SORT_DESCENDING

RETURN_FULL_QUERY

RETURN_WHERE

Methods

__construct(string $table)

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

void
clear()

Clears all scopes and conditions

static string
escapeField($field)

Escapes the passed mysql fieldname with backticks

static string
escapeValue($value)

Escapes the passed value for using it in a mysql query

string
getSQL()

Returns the full SQL string for this Query

array
getScopeLimit()

Return Limit

string
getScopeOrderBy()

Return ORDER BY part of the query

getScopeWhere()

Returns an array with all defined Conditions

getScopeWhereGroup()

Returns an array with all defined Conditions

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()

Builds the WHERE Condition SQL

groupBy($field)

Add a group by condition to the Query

$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

or(callable|null $callback = null)

Chain the next where() call with OR

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

Adds a orderBy condition to the Query

resetOrderBy()

Resets orderBy condition of the Query

select(string $selectField)

Adds a SELECT field 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)

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

void
triggerOnChange()

Trigger onChange event callbacks

$this
unscope(string $what = 'all')

Unscope Function to remove specific scopes of the query

void
unscopeFromQuery(Query $Query)

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

unscopeWhere($unscopeSpecificField = false)

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

whereEqual(string $field, string $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)

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

Adds a custom NEGATED WHERE Condition to the query

whereNotEqual(string $field, string $value)

Adds a NEGATED EQUAL WHERE Condition to the query

whereRaw($rawSQL)

Adds a RAW WHERE Condition to the query

Details

at line 58
__construct(string $table)

Query constructor.

Parameters

string $table

SQL Tablename which will be the primary Table for the Query

at line 389
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 305
void clear()

Clears all scopes and conditions

Return Value

void

at line 499
static string escapeField($field)

Escapes the passed mysql fieldname with backticks

Parameters

$field

string Fieldname

Return Value

string

Returns the escaped field name

at line 509
static string escapeValue($value)

Escapes the passed value for using it in a mysql query

Parameters

$value

string Value to escape

Return Value

string

Returns the escaped value

at line 381
string getSQL()

Returns the full SQL string for this Query

Return Value

string

at line 433
array getScopeLimit()

Return Limit

Return Value

array

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

at line 421
string getScopeOrderBy()

Return ORDER BY part of the query

Return Value

string

at line 406
Condition[] getScopeWhere()

Returns an array with all defined Conditions

Return Value

Condition[]

at line 413
ConditionGroup[] getScopeWhereGroup()

Returns an array with all defined Conditions

Return Value

ConditionGroup[]

at line 445
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 455
string getWhereSQL()

Builds the WHERE Condition SQL

Return Value

string

at line 263
Query groupBy($field)

Add a group by condition to the Query

Parameters

$field

SQL Fieldname

Return Value

Query

Query

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

Set Limit on Query

Parameters

int $length
int $offset

Return Value

$this

at line 252
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 230
Query or(callable|null $callback = null)

Chain the next where() call with OR

Parameters

callable|null $callback

Return Value

Query

at line 286
Query orderBy(string $field, string $sortDirection = self::SORT_ASCENDING)

Adds a orderBy condition to the Query

Parameters

string $field

SQL Fieldname

string $sortDirection

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

Return Value

Query

$this

at line 274
Query resetOrderBy()

Resets orderBy condition of the Query

Return Value

Query

$this

at line 113
Query select(string $selectField)

Adds a SELECT field to the query

Parameters

string $selectField

SQL Field to select

Return Value

Query

at line 89
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 69
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 104
static Query table(string $table)

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

Parameters

string $table

SQL Tablename

Return Value

Query

at line 77
void triggerOnChange()

Trigger onChange event callbacks

Return Value

void

at line 321
$this unscope(string $what = 'all')

Unscope Function to remove specific scopes of the query

Parameters

string $what

Return Value

$this

at line 358
void unscopeFromQuery(Query $Query)

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

Parameters

Query $Query

Return Value

void

at line 343
unscopeWhere($unscopeSpecificField = false)

Removes all Where Conditions or the Conditions for a specific field

Parameters

$unscopeSpecificField

at line 126
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 188
Query whereCondition(Condition $condition)

Adds a Condition object as condition

Parameters

Condition $condition

Condition object

Return Value

Query

at line 151
Query whereEqual(string $field, string $value)

Adds a EQUAL WHERE Condition to the query

Parameters

string $field

SQL Fieldname

string $value

Expected value

Return Value

Query

$this

at line 200
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 139
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 163
Query whereNotEqual(string $field, string $value)

Adds a NEGATED EQUAL WHERE Condition to the query

Parameters

string $field

SQL Fieldname

string $value

Expected value

Return Value

Query

$this

at line 177
Query whereRaw($rawSQL)

Adds a RAW WHERE Condition to the query

Parameters

$rawSQL

Return Value

Query

$this