Bitrix API

Query

Query builder for Entities.

Virtual WHERE methods (proxy to Filter):

Tags
see
ConditionTree::where()
see
ConditionTree::whereNot()
see
ConditionTree::whereColumn()
see
ConditionTree::whereNull()
see
ConditionTree::whereNotNull()
see
ConditionTree::whereIn()
see
ConditionTree::whereNotIn()
see
ConditionTree::whereBetween()
see
ConditionTree::whereNotBetween()
see
ConditionTree::whereLike()
see
ConditionTree::whereNotLike()
see
ConditionTree::whereExists()
see
ConditionTree::whereNotExists()
see
ConditionTree::whereMatch()
see
ConditionTree::whereNotMatch()
see
ConditionTree::whereExpr()

Virtual HAVING methods (proxy to Filter):

see
ConditionTree::where()
see
ConditionTree::whereNot()
see
ConditionTree::whereColumn()
see
ConditionTree::whereNull()
see
ConditionTree::whereNotNull()
see
ConditionTree::whereIn()
see
ConditionTree::whereNotIn()
see
ConditionTree::whereBetween()
see
ConditionTree::whereNotBetween()
see
ConditionTree::whereLike()
see
ConditionTree::whereNotLike()
see
ConditionTree::whereExists()
see
ConditionTree::whereNotExists()

Table of Contents

Methods

__call()  : $this
__clone()  : mixed
__construct()  : mixed
addFilter()  : $this
Adds a filter for WHERE clause
addGroup()  : $this
Adds a field to the list of fields for GROUP BY clause
addOrder()  : $this
Adds a filed to the list of fields for ORDER BY clause
addSelect()  : $this
Adds a field for SELECT clause
addUnionOrder()  : $this
General order for all the union queries.
booleanStrongEqualityCallback()  : mixed
buildFilterSql()  : string
Builds SQL filter conditions for WHERE.
cacheJoins()  : $this
Enables or disables caching of queries with joins.
countTotal()  : mixed
dataDoublingCallback()  : mixed
disableDataDoubling()  : $this
Replaces all 1:N relations in filter to ID IN (subquery SELECT ID FROM <1:N relation>) Available for Entities with 1 primary field only
disablePrivateFields()  : $this
Restricts private fields in query
dump()  : mixed
enableDataDoubling()  : $this
enablePrivateFields()  : $this
Allows private fields in query
exec()  : Result
Builds and executes the query and returns the result
expr()  : Expression
Used to create ExpressionField in a short way.
fetch()  : array<string|int, mixed>|false
Short alias for $result->fetch()
fetchAll()  : array<string|int, mixed>
Short alias for $result->fetchAll()
fetchCollection()  : null
Short alias for $result->fetchCollection()
fetchDataModificationCallback()  : mixed
Being called in Db\Result as a data fetch modifier
fetchObject()  : null
Short alias for $result->fetchObject()
filter()  : ConditionTree
Returns new instance of Filter.
getChains()  : array<string|int, mixed>|array<string|int, Chain>
getEntity()  : mixed
getFilter()  : array<string|int, mixed>
Returns an array of filters for WHERE clause
getFilterChains()  : array<string|int, mixed>|array<string|int, Chain>
getFilterHandler()  : ConditionTree
getGroup()  : array<string|int, mixed>
Returns an array of fields for GROUP BY clause
getGroupChains()  : array<string|int, mixed>|array<string|int, Chain>
getHavingChains()  : array<string|int, mixed>|array<string|int, Chain>
getHiddenChains()  : array<string|int, mixed>
getInitAlias()  : string
getJoinMap()  : mixed
getLastQuery()  : string
Returns last executed query string
getLimit()  : null|int
Returns a limit
getOffset()  : null|int
Returns an offset
getOrder()  : array<string|int, mixed>
Returns an array of fields for ORDER BY clause
getOrderChains()  : array<string|int, mixed>|array<string|int, Chain>
getQuery()  : string
Builds and returns SQL query string
getRegisteredChain()  : Chain|bool
getReplacedAliases()  : mixed
getRuntimeChains()  : array<string|int, Chain>
getSelect()  : array<string|int, mixed>
Returns an array of fields for SELECT clause
getSelectChains()  : array<string|int, mixed>|array<string|int, Chain>
getTableAliasPostfix()  : mixed
getWhereChains()  : array<string|int, mixed>|array<string|int, Chain>
hasAggregation()  : mixed
hasBackReference()  : bool
hasDistinct()  : mixed
having()  : $this
havingBetween()  : $this
havingColumn()  : $this
havingExists()  : $this
havingIn()  : $this
havingLike()  : $this
havingNot()  : $this
havingNotBetween()  : $this
havingNotExists()  : $this
havingNotIn()  : $this
havingNotLike()  : $this
havingNotNull()  : $this
havingNull()  : $this
isFetchModificationRequired()  : bool
Check if fetch data modification required, also caches modifier-callbacks
isFieldPrivate()  : bool
isPrivateFieldsEnabled()  : bool
nullEqualityCallback()  : mixed
queryCountTotal()  : mixed
quoteTableSource()  : string
registerChain()  : mixed
registerRuntimeField()  : $this
Adds a runtime field (being created dynamically, opposite to being described statically in the entity map)
setCacheTtl()  : mixed
setCustomBaseTableAlias()  : $this
Sets a custom alias for the table of the init entity
setDistinct()  : mixed
setFilter()  : $this
Sets a list of filters for WHERE clause
setFilterChains()  : mixed
setFilterHandlerChains()  : mixed
setGroup()  : $this
Sets a list of fields in GROUP BY clause
setLimit()  : $this
Sets a limit for LIMIT n clause
setOffset()  : $this
Sets an offset for LIMIT n, m clause
setOrder()  : $this
Sets a list of fields for ORDER BY clause.
setSelect()  : Query
Sets a list of fields for SELECT clause
setTableAliasPostfix()  : mixed
setUnionLimit()  : $this
General limit for all the union queries.
setUnionOffset()  : $this
General offset for all the union queries.
setUnionOrder()  : $this
General order for all the union queries.
union()  : $this
Puts additional query to union with current.
unionAll()  : $this
Puts additional query to union (all) with current.
where()  : $this
whereBetween()  : $this
whereColumn()  : $this
whereExists()  : $this
whereExpr()  : $this
whereIn()  : $this
whereLike()  : $this
whereMatch()  : $this
whereNot()  : $this
whereNotBetween()  : $this
whereNotExists()  : $this
whereNotIn()  : $this
whereNotLike()  : $this
whereNotMatch()  : $this
whereNotNull()  : $this
whereNull()  : $this

Methods

__call()

public __call(mixed $method, mixed $arguments) : $this
Parameters
$method : mixed
$arguments : mixed
Tags
throws
SystemException
Return values
$this

__clone()

public __clone() : mixed

__construct()

public __construct(Entity|Query|string $source) : mixed
Parameters
$source : Entity|Query|string
Tags
throws
ArgumentException
throws
SystemException

addFilter()

Adds a filter for WHERE clause

public addFilter(string $key, mixed $value) : $this
Parameters
$key : string
$value : mixed
Return values
$this

addGroup()

Adds a field to the list of fields for GROUP BY clause

public addGroup(mixed $group) : $this
Parameters
$group : mixed
Return values
$this

addOrder()

Adds a filed to the list of fields for ORDER BY clause

public addOrder(string $definition[, string $order = 'ASC' ]) : $this
Parameters
$definition : string
$order : string = 'ASC'
Tags
throws
ArgumentException
throws
SystemException
Return values
$this

addSelect()

Adds a field for SELECT clause

public addSelect(mixed $definition[, string $alias = '' ]) : $this
Parameters
$definition : mixed

Field

$alias : string = ''

Field alias like SELECT field AS alias

Return values
$this

addUnionOrder()

General order for all the union queries.

public addUnionOrder(string $definition[, string $order = 'ASC' ]) : $this

Has the same format as Query::addOrder().

Parameters
$definition : string
$order : string = 'ASC'
Tags
see
Query::addOrder()
throws
ArgumentException
throws
SystemException
Return values
$this

booleanStrongEqualityCallback()

public booleanStrongEqualityCallback(mixed $field, mixed $operation, mixed $value) : mixed
Parameters
$field : mixed
$operation : mixed
$value : mixed

buildFilterSql()

Builds SQL filter conditions for WHERE.

public static buildFilterSql(Entity $entity, array<string|int, mixed>|ConditionTree $filter) : string

Useful for external calls: building SQL for mass UPDATEs or DELETEs

Parameters
$entity : Entity
$filter : array<string|int, mixed>|ConditionTree

the same format as for setFilter/where

Tags
throws
ArgumentException
throws
SystemException
Return values
string

cacheJoins()

Enables or disables caching of queries with joins.

public cacheJoins(bool $mode) : $this
Parameters
$mode : bool
Return values
$this

countTotal()

public countTotal([mixed $count = null ]) : mixed
Parameters
$count : mixed = null

dataDoublingCallback()

public dataDoublingCallback(mixed $field, mixed $operation, mixed $value) : mixed
Parameters
$field : mixed
$operation : mixed
$value : mixed

disableDataDoubling()

Replaces all 1:N relations in filter to ID IN (subquery SELECT ID FROM <1:N relation>) Available for Entities with 1 primary field only

public disableDataDoubling() : $this
Return values
$this

disablePrivateFields()

Restricts private fields in query

public disablePrivateFields() : $this
Return values
$this

dump()

public dump() : mixed

enableDataDoubling()

public enableDataDoubling() : $this
Tags
see
disableDataDoubling
Return values
$this

enablePrivateFields()

Allows private fields in query

public enablePrivateFields() : $this
Return values
$this

exec()

Builds and executes the query and returns the result

public exec() : Result
Tags
throws
ObjectPropertyException
throws
SystemException
Return values
Result

expr()

Used to create ExpressionField in a short way.

public static expr([string|null $alias = null ]) : Expression
Parameters
$alias : string|null = null

Name for ExpressionField

Tags
see
ConditionTree::where()
Return values
Expression

fetch()

Short alias for $result->fetch()

public fetch([Converter|null $converter = null ]) : array<string|int, mixed>|false
Parameters
$converter : Converter|null = null
Tags
throws
ObjectPropertyException
throws
SystemException
Return values
array<string|int, mixed>|false

fetchAll()

Short alias for $result->fetchAll()

public fetchAll([Converter|null $converter = null ]) : array<string|int, mixed>
Parameters
$converter : Converter|null = null
Tags
throws
ObjectPropertyException
throws
SystemException
Return values
array<string|int, mixed>

fetchCollection()

Short alias for $result->fetchCollection()

public fetchCollection() : null
Tags
throws
ObjectPropertyException
throws
SystemException
Return values
null

Actual type should be annotated by orm:annotate

fetchDataModificationCallback()

Being called in Db\Result as a data fetch modifier

public fetchDataModificationCallback(mixed &$data) : mixed
Parameters
$data : mixed

fetchObject()

Short alias for $result->fetchObject()

public fetchObject() : null
Tags
throws
ArgumentException
throws
ObjectPropertyException
throws
SystemException
Return values
null

Actual type should be annotated by orm:annotate

filter()

Returns new instance of Filter.

public static filter() : ConditionTree

Usage: Query::filter()->where(...)

Alternatively short calls Query::where* can be used.

Tags
see
Query::where()
Return values
ConditionTree

getChains()

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

getEntity()

public getEntity() : mixed

getFilter()

Returns an array of filters for WHERE clause

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

getFilterChains()

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

getGroup()

Returns an array of fields for GROUP BY clause

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

getGroupChains()

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

getHavingChains()

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

getHiddenChains()

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

getInitAlias()

public getInitAlias([bool $withPostfix = true ]) : string
Parameters
$withPostfix : bool = true
Tags
throws
SystemException
Return values
string

getJoinMap()

public getJoinMap() : mixed

getLastQuery()

Returns last executed query string

public static getLastQuery() : string
Return values
string

getLimit()

Returns a limit

public getLimit() : null|int
Return values
null|int

getOffset()

Returns an offset

public getOffset() : null|int
Return values
null|int

getOrder()

Returns an array of fields for ORDER BY clause

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

getOrderChains()

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

getQuery()

Builds and returns SQL query string

public getQuery([bool $forceObjectPrimary = false ]) : string
Parameters
$forceObjectPrimary : bool = false
Tags
throws
ArgumentException
throws
SystemException
Return values
string

getRegisteredChain()

public getRegisteredChain(mixed $key[, bool $force_create = false ]) : Chain|bool
Parameters
$key : mixed
$force_create : bool = false
Tags
throws
ArgumentException
throws
SystemException
Return values
Chain|bool

getReplacedAliases()

public getReplacedAliases() : mixed

getRuntimeChains()

public getRuntimeChains() : array<string|int, Chain>
Return values
array<string|int, Chain>

getSelect()

Returns an array of fields for SELECT clause

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

getSelectChains()

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

getTableAliasPostfix()

public getTableAliasPostfix() : mixed

getWhereChains()

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

hasAggregation()

public hasAggregation() : mixed

hasBackReference()

public hasBackReference() : bool
Tags
throws
SystemException
Return values
bool

hasDistinct()

public hasDistinct() : mixed

having()

public having(mixed ...$filter) : $this
Parameters
$filter : mixed
Return values
$this

havingBetween()

public havingBetween(mixed $column, mixed $valueMin, mixed $valueMax) : $this
Parameters
$column : mixed
$valueMin : mixed
$valueMax : mixed
Return values
$this

havingColumn()

public havingColumn(mixed ...$filter) : $this
Parameters
$filter : mixed
Return values
$this

havingExists()

public havingExists(mixed $query) : $this
Parameters
$query : mixed
Return values
$this

havingIn()

public havingIn(mixed $column, mixed $values) : $this
Parameters
$column : mixed
$values : mixed
Return values
$this

havingLike()

public havingLike(mixed $column, mixed $value) : $this
Parameters
$column : mixed
$value : mixed
Return values
$this

havingNot()

public havingNot(mixed ...$filter) : $this
Parameters
$filter : mixed
Return values
$this

havingNotBetween()

public havingNotBetween(mixed $column, mixed $valueMin, mixed $valueMax) : $this
Parameters
$column : mixed
$valueMin : mixed
$valueMax : mixed
Return values
$this

havingNotExists()

public havingNotExists(mixed $query) : $this
Parameters
$query : mixed
Return values
$this

havingNotIn()

public havingNotIn(mixed $column, mixed $values) : $this
Parameters
$column : mixed
$values : mixed
Return values
$this

havingNotLike()

public havingNotLike(mixed $column, mixed $value) : $this
Parameters
$column : mixed
$value : mixed
Return values
$this

havingNotNull()

public havingNotNull(mixed $column) : $this
Parameters
$column : mixed
Return values
$this

havingNull()

public havingNull(mixed $column) : $this
Parameters
$column : mixed
Return values
$this

isFetchModificationRequired()

Check if fetch data modification required, also caches modifier-callbacks

public isFetchModificationRequired() : bool
Tags
throws
SystemException
Return values
bool

isFieldPrivate()

public static isFieldPrivate(Field|IReadable $field) : bool
Parameters
$field : Field|IReadable
Tags
throws
ArgumentException
throws
SystemException
Return values
bool

isPrivateFieldsEnabled()

public isPrivateFieldsEnabled() : bool
Return values
bool

nullEqualityCallback()

public nullEqualityCallback(mixed $field, mixed $operation, mixed $value) : mixed
Parameters
$field : mixed
$operation : mixed
$value : mixed

queryCountTotal()

public queryCountTotal() : mixed

quoteTableSource()

public quoteTableSource(mixed $source) : string
Parameters
$source : mixed
Tags
throws
SystemException
Return values
string

registerChain()

public registerChain(mixed $section, Chain $chain[, mixed $opt_key = null ]) : mixed
Parameters
$section : mixed
$chain : Chain
$opt_key : mixed = null

registerRuntimeField()

Adds a runtime field (being created dynamically, opposite to being described statically in the entity map)

public registerRuntimeField(string|null|Field $name[, array<string|int, mixed>|Field $fieldInfo = null ]) : $this
Parameters
$name : string|null|Field
$fieldInfo : array<string|int, mixed>|Field = null
Tags
throws
ArgumentException
throws
SystemException
Return values
$this

setCacheTtl()

public setCacheTtl(mixed $ttl) : mixed
Parameters
$ttl : mixed

setCustomBaseTableAlias()

Sets a custom alias for the table of the init entity

public setCustomBaseTableAlias(string $alias) : $this
Parameters
$alias : string
Return values
$this

setDistinct()

public setDistinct([mixed $distinct = true ]) : mixed
Parameters
$distinct : mixed = true

setFilter()

Sets a list of filters for WHERE clause

public setFilter(array<string|int, mixed> $filter) : $this
Parameters
$filter : array<string|int, mixed>
Return values
$this

setFilterChains()

public setFilterChains(mixed &$filter[, string $section = 'filter' ]) : mixed
Parameters
$filter : mixed
$section : string = 'filter'
Tags
throws
ArgumentException
throws
SystemException

setFilterHandlerChains()

public setFilterHandlerChains(ConditionTree $where[, string $section = 'filter' ]) : mixed
Parameters
$where : ConditionTree
$section : string = 'filter'
Tags
throws
ArgumentException
throws
SystemException

setGroup()

Sets a list of fields in GROUP BY clause

public setGroup(mixed $group) : $this
Parameters
$group : mixed
Return values
$this

setLimit()

Sets a limit for LIMIT n clause

public setLimit(int $limit) : $this
Parameters
$limit : int
Return values
$this

setOffset()

Sets an offset for LIMIT n, m clause

public setOffset(int $offset) : $this
Parameters
$offset : int
Return values
$this

setOrder()

Sets a list of fields for ORDER BY clause.

public setOrder(mixed $order) : $this

Format: setOrder('ID') -- ORDER BY ID ASC setOrder(['ID' => 'DESC', 'NAME' => 'ASC]) -- ORDER BY ID DESC, NAME ASC

Parameters
$order : mixed
Tags
throws
ArgumentException
throws
SystemException
Return values
$this

setSelect()

Sets a list of fields for SELECT clause

public setSelect(array<string|int, mixed> $select) : Query
Parameters
$select : array<string|int, mixed>
Return values
Query

setTableAliasPostfix()

public setTableAliasPostfix(mixed $postfix) : mixed
Parameters
$postfix : mixed

setUnionLimit()

General limit for all the union queries.

public setUnionLimit(mixed $limit) : $this
Parameters
$limit : mixed
Tags
throws
SystemException
Return values
$this

setUnionOffset()

General offset for all the union queries.

public setUnionOffset(mixed $offset) : $this
Parameters
$offset : mixed
Tags
throws
SystemException
Return values
$this

setUnionOrder()

General order for all the union queries.

public setUnionOrder(mixed $order) : $this

Has the same format as Query::setOrder().

Parameters
$order : mixed
Tags
see
Query::setOrder()
throws
SystemException
Return values
$this

union()

Puts additional query to union with current.

public union() : $this

Accepts one or more Query / SqlExpression.

Tags
throws
ArgumentException
throws
SystemException
Return values
$this

unionAll()

Puts additional query to union (all) with current.

public unionAll() : $this

Accepts one or more Query / SqlExpression.

Tags
throws
ArgumentException
throws
SystemException
Return values
$this

where()

public where(mixed ...$filter) : $this
Parameters
$filter : mixed
Return values
$this

whereBetween()

public whereBetween(mixed $column, mixed $valueMin, mixed $valueMax) : $this
Parameters
$column : mixed
$valueMin : mixed
$valueMax : mixed
Return values
$this

whereColumn()

public whereColumn(mixed ...$filter) : $this
Parameters
$filter : mixed
Return values
$this

whereExists()

public whereExists(mixed $query) : $this
Parameters
$query : mixed
Return values
$this

whereExpr()

public whereExpr(mixed $expr, mixed $arguments) : $this
Parameters
$expr : mixed
$arguments : mixed
Return values
$this

whereIn()

public whereIn(mixed $column, mixed $values) : $this
Parameters
$column : mixed
$values : mixed
Return values
$this

whereLike()

public whereLike(mixed $column, mixed $value) : $this
Parameters
$column : mixed
$value : mixed
Return values
$this

whereMatch()

public whereMatch(mixed $column, mixed $value) : $this
Parameters
$column : mixed
$value : mixed
Return values
$this

whereNot()

public whereNot(mixed ...$filter) : $this
Parameters
$filter : mixed
Return values
$this

whereNotBetween()

public whereNotBetween(mixed $column, mixed $valueMin, mixed $valueMax) : $this
Parameters
$column : mixed
$valueMin : mixed
$valueMax : mixed
Return values
$this

whereNotExists()

public whereNotExists(mixed $query) : $this
Parameters
$query : mixed
Return values
$this

whereNotIn()

public whereNotIn(mixed $column, mixed $values) : $this
Parameters
$column : mixed
$values : mixed
Return values
$this

whereNotLike()

public whereNotLike(mixed $column, mixed $value) : $this
Parameters
$column : mixed
$value : mixed
Return values
$this

whereNotMatch()

public whereNotMatch(mixed $column, mixed $value) : $this
Parameters
$column : mixed
$value : mixed
Return values
$this

whereNotNull()

public whereNotNull(mixed $column) : $this
Parameters
$column : mixed
Return values
$this

whereNull()

public whereNull(mixed $column) : $this
Parameters
$column : mixed
Return values
$this

        
On this page

Search results