Documentation

Core_QueryBuilder_Select extends Core_QueryBuilder_Selection

Query builder. SELECT Database Abstraction Layer (DBAL)

http://dev.mysql.com/doc/refman/5.7/en/select.html

Subqueries http://dev.mysql.com/doc/refman/5.7/en/subqueries.html

The Subquery as Scalar Operand http://dev.mysql.com/doc/refman/5.7/en/scalar-subqueries.html // SELECT (SELECT MAX(column2) FROM t2) FROM t1 $oCore_QueryBuilder_Select2 = Core_QueryBuilder::select('MAX(column2)')->from('t2'); $oCore_QueryBuilder_Select = Core_QueryBuilder::select($oCore_QueryBuilder_Select2)->from('t1');

Comparisons Using Subqueries http://dev.mysql.com/doc/refman/5.7/en/comparisons-using-subqueries.html

// SELECT * FROM `t1` WHERE `column1` = (SELECT MAX(`column2`) FROM `t2`) $oCore_QueryBuilder_Select2 = Core_QueryBuilder::select('MAX(column2)')->from('t2');

$oCore_QueryBuilder_Select = Core_QueryBuilder::select()->from('t1') ->where('column1', '=', $oCore_QueryBuilder_Select2);

Tags
see
Core_QueryBuilder_Selection
subpackage

Core\Querybuilder

version
7.x
author

Hostmake LLC

copyright

© 2005-2022 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru

Table of Contents

$_dataBase  : mixed
DataBase
$_defaultOperator  : string
Default operator between conditions
$_distinct  : bool
DISTINCT
$_from  : array<string|int, mixed>
FROM
$_groupBy  : array<string|int, mixed>
GROUP BY
$_having  : array<string|int, mixed>
HAVING
$_highPriority  : bool
HIGH_PRIORITY
$_indexHints  : array<string|int, mixed>
Index Hints
$_join  : array<string|int, mixed>
JOIN
$_limit  : mixed
LIMIT
$_offset  : mixed
OFFSET
$_offsetPostgreSQLSyntax  : bool
Offset compatibility with PostgreSQL, default TRUE
$_operator  : string
Current operator
$_orderBy  : array<string|int, mixed>
ORDER BY
$_partition  : array<string|int, mixed>
PARTITION
$_queryType  : mixed
DataBase Query Type 0 - SELECT
$_select  : array<string|int, mixed>
SELECT
$_sqlCalcFoundRows  : bool
SQL_CALC_FOUND_ROWS
$_straightJoin  : bool
STRAIGHT_JOIN
$_unbuffered  : mixed
Query without fetching and buffering the result rows
$_union  : array<string|int, mixed>
Array of Core_QueryBuilder_Select's
$_unionLimit  : mixed
UNION LIMIT
$_unionOffset  : mixed
UNION OFFSET
$_unionOrderBy  : array<string|int, mixed>
UNION ORDER BY
$_where  : array<string|int, mixed>
WHERE
__call()  : mixed
Triggered when invoking inaccessible methods in an object context
__construct()  : mixed
Constructor.
__set()  : self
Run when writing data to inaccessible properties
asAssoc()  : self
Set result type as an array
asObject()  : self
Set result type as an object with className
build()  : string
Build the SQL query
chunk()  : bool
Retrieve a small chunk and feeds each one into $callback for processing. It stops looping when $callback returns FALSE
clear()  : self
Clear
clearFrom()  : self
Clear FROM
clearGroupBy()  : self
Clear GROUP BY list
clearHaving()  : self
Clear HAVING list
clearIndexHints()  : self
Clear Index Hints
clearJoin()  : self
Clear JOIN
clearLimit()  : self
Clear LIMIT
clearOffset()  : self
Clear OFFSET
clearOrderBy()  : self
Clear ORDER BY
clearSelect()  : self
Clear SELECT list
clearWhere()  : self
Clear WHERE list
close()  : self
Close bracket in WHERE
columns()  : self
Add columns for select
crossJoin()  : self
In MySQL, CROSS JOIN is a syntactic equivalent to INNER JOIN (they can replace each other).
deleteFirstHaving()  : self
Delete first HAVING condition
deleteFirstWhere()  : self
Delete first WHERE condition
deleteLastHaving()  : self
Delete last HAVING condition
deleteLastWhere()  : self
Delete last WHERE condition
distinct()  : self
Set DISTINCT
execute()  : Core_DataBase
Execute query
firstJoin()  : self
Add INNER JOIN first
firstLeftJoin()  : self
Add LEFT OUTER JOIN first
from()  : self
Set FROM
getDataBase()  : Core_DataBase
Get DataBase
getFoundRows()  : int
Get FOUND_ROWS()
getFrom()  : array<string|int, mixed>
Get FROM
getGroupBy()  : array<string|int, mixed>
Get GROUP BY
getJoin()  : array<string|int, mixed>
Get JOIN
getOrderBy()  : array<string|int, mixed>
Get ORDER BY
getSelect()  : array<string|int, mixed>
Get SELECT
getWhere()  : array<string|int, mixed>
Get WHERE
group()  : self
GROUP BY
groupBy()  : self
Set GROUP BY
having()  : self
Add HAVING
havingClose()  : self
Close bracket in HAVING
havingOpen()  : self
Open bracket in HAVING
havingRaw()  : self
Add raw expression into HAVING.
highPriority()  : self
Set HIGH_PRIORITY
indexHint()  : self
Add Index Hints https://dev.mysql.com/doc/refman/5.7/en/index-hints.html
isHighPriority()  : bool
Check if HIGH_PRIORITY was set
isStraightJoin()  : bool
Check if STRAIGHT_JOIN was set
join()  : self
INNER JOIN
leftJoin()  : self
LEFT OUTER JOIN
limit()  : self
Set limit and offset
naturalJoin()  : self
<code> // NATURAL JOIN `join1` $Core_QueryBuilder_Select->naturalJoin('join1'); </code>
offset()  : self
Set offset
offsetPostgreSQLSyntax()  : mixed
Offset compatibility with PostgreSQL, default TRUE $param boolean $compatible
open()  : self
Open bracket in WHERE
order()  : mixed
Order options
orderBy()  : self
Set order column and direction
orderByRaw()  : self
Add raw expression into ORDER BY.
orHaving()  : self
Add OR and HAVING, e.g. HAVING ... OR $column $expression $value
orWhere()  : self
Add OR and WHERE, e.g. WHERE ... OR $column $expression $value
orWhereBetween()  : self
Add OR and WHERE $column BETWEEN x AND y
orWhereColumn()  : self
Set OR and verify two columns
orWhereIn()  : self
Add OR and WHERE $column IN (x, y)
orWhereIsNotNull()  : self
Add OR and WHERE $column IS NOT NULL
orWhereIsNull()  : self
Add OR and WHERE $column IS NULL
orWhereNotBetween()  : self
Add OR and WHERE $column NOT BETWEEN x AND y
orWhereNotIn()  : self
Add OR and WHERE $column NOT IN (x, y)
partition()  : Core_QueryBuilder_Select
Set PARTITION
quoteTable()  : array<string|int, mixed>
Quote columns
rightJoin()  : self
RIGHT OUTER JOIN
rightJoinFirst()  : self
Add RIGHT OUTER JOIN first
select()  : mixed
Alias for columns()
selectDistinct()  : self
Set DISTINCT and add columns for select
setAnd()  : self
Set operator as AND
setDataBase()  : Core_QueryBuilder_Statement
Set DataBase
setDefaultOperator()  : self
Set operator as a default operator
setOperator()  : self
Set operator as a default operator
setOr()  : self
Set operator as OR
sqlCalcFoundRows()  : self
Set SQL_CALC_FOUND_ROWS
straightJoin()  : self
Set STRAIGHT_JOIN
unbuffered()  : self
Query without fetching and buffering the result rows
union()  : self
UNION is used to combine the result from multiple SELECT statements into a single result set.
unionAll()  : self
UNION ALL is used to combine the result from multiple SELECT statements into a single result set.
unionLimit()  : mixed
LIMIT for UNION
unionOffset()  : selfion
Set UNION offset
unionOrderBy()  : mixed
ORDER BY for UNION
where()  : self
Add WHERE
whereBetween()  : self
Add WHERE $column BETWEEN x AND y
whereColumn()  : self
Verify two columns
whereIn()  : self
Add WHERE $column IN (x, y)
whereIsNotNull()  : self
Add WHERE $column IS NOT NULL
whereIsNull()  : self
Add WHERE $column IS NULL
whereNotBetween()  : self
Add WHERE $column NOT BETWEEN x AND y
whereNotIn()  : self
Add WHERE $column NOT IN (x, y)
whereRaw()  : self
Add raw expression into WHERE.
_buildExpression()  : string
Build WHERE or HAVING expression
_buildIndexHint()  : string
Build INDEX expression
_buildJoin()  : string
Build JOIN expression
_buildOrderBy()  : string
Build ORDER BY expression
_buildWhere()  : string
Build expression for one condition
_isObjectSelect()  : bool
Is $object Core_QueryBuilder_Select
_join()  : self
http://dev.mysql.com/doc/refman/5.7/en/join.html
_quoteColumns()  : array<string|int, mixed>
Quote columns
_quoteTables()  : array<string|int, mixed>
Quote columns
_quoteValues()  : array<string|int, mixed>
Quote arary of values

Properties

$_dataBase

DataBase

protected mixed $_dataBase = \NULL

$_defaultOperator

Default operator between conditions

protected string $_defaultOperator = 'AND'

$_distinct

DISTINCT

protected bool $_distinct = \FALSE

$_from

FROM

protected array<string|int, mixed> $_from = array()

$_groupBy

GROUP BY

protected array<string|int, mixed> $_groupBy = array()

$_having

HAVING

protected array<string|int, mixed> $_having = array()

$_highPriority

HIGH_PRIORITY

protected bool $_highPriority = \FALSE

$_indexHints

Index Hints

protected array<string|int, mixed> $_indexHints = array()

$_join

JOIN

protected array<string|int, mixed> $_join = array()

$_limit

LIMIT

protected mixed $_limit = \NULL

$_offset

OFFSET

protected mixed $_offset = \NULL

$_offsetPostgreSQLSyntax

Offset compatibility with PostgreSQL, default TRUE

protected bool $_offsetPostgreSQLSyntax = \TRUE

$_operator

Current operator

protected string $_operator = ''

$_orderBy

ORDER BY

protected array<string|int, mixed> $_orderBy = array()

$_partition

PARTITION

protected array<string|int, mixed> $_partition = array()

$_queryType

DataBase Query Type 0 - SELECT

protected mixed $_queryType = 0

$_select

SELECT

protected array<string|int, mixed> $_select = array()

$_sqlCalcFoundRows

SQL_CALC_FOUND_ROWS

protected bool $_sqlCalcFoundRows = \FALSE

$_straightJoin

STRAIGHT_JOIN

protected bool $_straightJoin = \FALSE

$_unbuffered

Query without fetching and buffering the result rows

protected mixed $_unbuffered = \FALSE

$_union

Array of Core_QueryBuilder_Select's

protected array<string|int, mixed> $_union = array()

$_unionLimit

UNION LIMIT

protected mixed $_unionLimit = \NULL

$_unionOffset

UNION OFFSET

protected mixed $_unionOffset = \NULL

$_unionOrderBy

UNION ORDER BY

protected array<string|int, mixed> $_unionOrderBy = array()

$_where

WHERE

protected array<string|int, mixed> $_where = array()

Methods

__call()

Triggered when invoking inaccessible methods in an object context

public __call(string $name, array<string|int, mixed> $arguments) : mixed
Parameters
$name : string

method name

$arguments : array<string|int, mixed>

arguments

Return values
mixed

__construct()

Constructor.

public __construct([array<string|int, mixed> $args = array() ]) : mixed
$oCore_QueryBuilder_Select = Core_QueryBuilder::select('id', array('tableName.name', 'aliasName'));
Parameters
$args : array<string|int, mixed> = array()

list of arguments

Tags
see
columns()
Return values
mixed

__set()

Run when writing data to inaccessible properties

public __set(string $property, string $value) : self
Parameters
$property : string

property name

$value : string

property value

Return values
self

asAssoc()

Set result type as an array

public asAssoc() : self
Return values
self

asObject()

Set result type as an object with className

public asObject([mixed $className = NULL ]) : self
Parameters
$className : mixed = NULL

Object class name

Return values
self

build()

Build the SQL query

public build() : string
Return values
string

The SQL query

chunk()

Retrieve a small chunk and feeds each one into $callback for processing. It stops looping when $callback returns FALSE

public chunk(int $count, callable $callback[, bool $bCache = TRUE ]) : bool
Parameters
$count : int

chunk size

$callback : callable
$bCache : bool = TRUE

use cache

Return values
bool

clear()

Clear

public clear() : self
Return values
self

clearFrom()

Clear FROM

public clearFrom() : self
Return values
self

clearGroupBy()

Clear GROUP BY list

public clearGroupBy() : self
Return values
self

clearHaving()

Clear HAVING list

public clearHaving() : self
Return values
self

clearIndexHints()

Clear Index Hints

public clearIndexHints() : self
Return values
self

clearJoin()

Clear JOIN

public clearJoin() : self
Return values
self

clearLimit()

Clear LIMIT

public clearLimit() : self
Return values
self

clearOffset()

Clear OFFSET

public clearOffset() : self
Return values
self

clearOrderBy()

Clear ORDER BY

public clearOrderBy() : self
Return values
self

clearSelect()

Clear SELECT list

public clearSelect() : self
Return values
self

clearWhere()

Clear WHERE list

public clearWhere() : self
Return values
self

close()

Close bracket in WHERE

public close() : self
Return values
self

columns()

Add columns for select

public columns() : self
// SELECT `id`, `name` $Core_QueryBuilder_Select->columns('id', 'name');

// SELECT id, name AS aliasName $Core_QueryBuilder_Select->columns('id', array('name', 'aliasName'));

// SELECT id, tablename.name AS aliasName $Core_QueryBuilder_Select->columns('id', array('tablename.name', 'aliasName'));

Return values
self

crossJoin()

In MySQL, CROSS JOIN is a syntactic equivalent to INNER JOIN (they can replace each other).

public crossJoin(string $table) : self

In standard SQL, they are not equivalent. INNER JOIN is used with an ON clause, CROSS JOIN is used otherwise.

// CROSS JOIN `join1` $Core_QueryBuilder_Select->crossJoin('join1');
Parameters
$table : string

table name

Return values
self

deleteFirstHaving()

Delete first HAVING condition

public deleteFirstHaving() : self
Return values
self

deleteFirstWhere()

Delete first WHERE condition

public deleteFirstWhere() : self
Return values
self

deleteLastHaving()

Delete last HAVING condition

public deleteLastHaving() : self
Return values
self

deleteLastWhere()

Delete last WHERE condition

public deleteLastWhere() : self
Return values
self

distinct()

Set DISTINCT

public distinct([bool $distinct = TRUE ]) : self
$oCore_QueryBuilder_Select = Core_QueryBuilder::select()->distinct();
Parameters
$distinct : bool = TRUE

DISTINCT option

Return values
self

firstJoin()

Add INNER JOIN first

public firstJoin(string $table, string $column[, string|null $expression = NULL ][, string|null $value = NULL ][, string|null $additionalConditions = NULL ]) : self
Parameters
$table : string

table name

$column : string

column name

$expression : string|null = NULL

expression

$value : string|null = NULL

value

$additionalConditions : string|null = NULL

additional conditions

Return values
self

firstLeftJoin()

Add LEFT OUTER JOIN first

public firstLeftJoin(string $table, string $column[, string|null $expression = NULL ][, string|null $value = NULL ][, string|null $additionalConditions = NULL ]) : self
Parameters
$table : string

table name

$column : string

column name

$expression : string|null = NULL

expression

$value : string|null = NULL

value

$additionalConditions : string|null = NULL

additional conditions

Return values
self

from()

Set FROM

public from() : self
// FROM `tableName` $oCore_QueryBuilder_Select = $Core_QueryBuilder_Select->from('tableName');

// FROM tableName AS tableNameAlias $oCore_QueryBuilder_Select = $Core_QueryBuilder_Select->from(array('tableName', 'tableNameAlias'));

Return values
self

getFoundRows()

Get FOUND_ROWS()

public getFoundRows() : int
$iCount = Core_QueryBuilder::select()->getFoundRows();
Return values
int

getFrom()

Get FROM

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

getGroupBy()

Get GROUP BY

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

getJoin()

Get JOIN

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

getOrderBy()

Get ORDER BY

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

getSelect()

Get SELECT

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

getWhere()

Get WHERE

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

group()

GROUP BY

public group(string $column) : self
Parameters
$column : string

column

Tags
see
groupBy()
Return values
self

groupBy()

Set GROUP BY

public groupBy() : self
// GROUP BY `field`, COUNT(`id`) $Core_QueryBuilder_Select->groupBy('field1')->groupBy('COUNT(id)');
Return values
self

having()

Add HAVING

public having(string $column, string $expression, string $value) : self
// HAVING `a1` > '2' $Core_QueryBuilder_Select->having('a1', '>', '2');

// HAVING a4 IN (17, 19, NULL, 'NULL') $Core_QueryBuilder_Select->having('a4', 'IN', array(17,19, NULL, 'NULL'));

// HAVING a7 BETWEEN 1 AND 10 $Core_QueryBuilder_Select->having('a7', 'BETWEEN', array(1, 10));

Parameters
$column : string

column

$expression : string

expression

$value : string

value

Return values
self

havingClose()

Close bracket in HAVING

public havingClose() : self
Return values
self

havingOpen()

Open bracket in HAVING

public havingOpen() : self
Return values
self

havingRaw()

Add raw expression into HAVING.

public havingRaw(string $expr) : self

ATTENTION! Danger, you should escape the query yourself!

// HAVING `a1` > 2 $Core_QueryBuilder_Select->havingRaw("`a1` > 2");
Parameters
$expr : string

expression

Return values
self

highPriority()

Set HIGH_PRIORITY

public highPriority([bool $value = TRUE ]) : self
$oCore_QueryBuilder_Select = Core_QueryBuilder::select()->highPriority();
Parameters
$value : bool = TRUE
Return values
self

indexHint()

Add Index Hints https://dev.mysql.com/doc/refman/5.7/en/index-hints.html

public indexHint(string $tableName, array<string|int, mixed> $options) : self
// USE INDEX (`col1_index`) $Core_QueryBuilder_Select->indexHint('table1', array('USE INDEX', 'col1_index'));

// USE INDEX FOR JOIN (col1_index, col2_index) $Core_QueryBuilder_Select->indexHint('table1', array('USE INDEX', 'FOR JOIN', array('col1_index', 'col2_index')));

Parameters
$tableName : string

table name

$options : array<string|int, mixed>

[$action, $index_list] or [$action, $for, $index_list]

Return values
self

isHighPriority()

Check if HIGH_PRIORITY was set

public isHighPriority() : bool
Return values
bool

isStraightJoin()

Check if STRAIGHT_JOIN was set

public isStraightJoin() : bool
Return values
bool

join()

INNER JOIN

public join(string $table, string $column[, string|null $expression = NULL ][, string|null $value = NULL ][, string|null $additionalConditions = NULL ]) : self
// INNER JOIN `join1` USING (`join_field`) $Core_QueryBuilder_Select->join('join1', 'join_field');

// INNER JOIN jointable.join1 ON join_field = join_field2 $Core_QueryBuilder_Select->join('jointable.join1', 'join_field1', '=', 'join_field2');

// INNER JOIN jointable.join1 ON join_field = join_field2 AND A = '123' AND B = 'xyz' $Core_QueryBuilder_Select->join('jointable.join1', 'join_field1', '=', 'join_field2', array( array('AND' => array('A', '=', '123')), array('AND' => array('B', '=', 'xyz')) ));

Parameters
$table : string

table name

$column : string

column name

$expression : string|null = NULL

expression

$value : string|null = NULL

value

$additionalConditions : string|null = NULL

additional conditions

Return values
self

leftJoin()

LEFT OUTER JOIN

public leftJoin(string $table, string $column[, string|null $expression = NULL ][, string|null $value = NULL ][, string|null $additionalConditions = NULL ]) : self
// LEFT OUTER JOIN `join1` USING (`join_field2`) $Core_QueryBuilder_Select->leftJoin('join1', 'join_field2');

// LEFT OUTER JOIN jointable.join1 ON join_field = join_field2 $Core_QueryBuilder_Select->leftJoin('jointable.join1', 'join_field', '=', 'join_field2');

Parameters
$table : string

table name

$column : string

column name

$expression : string|null = NULL

expression

$value : string|null = NULL

value

$additionalConditions : string|null = NULL

additional conditions

Return values
self

limit()

Set limit and offset

public limit(int $arg1[, int $arg2 = NULL ]) : self
// LIMIT 10 $Core_QueryBuilder_Select->limit(10);

// LIMIT 10 OFFSET 0 $Core_QueryBuilder_Select->limit(0, 10);

Parameters
$arg1 : int
$arg2 : int = NULL
Return values
self

naturalJoin()

<code> // NATURAL JOIN `join1` $Core_QueryBuilder_Select->naturalJoin('join1'); </code>

public naturalJoin(string $table) : self
Parameters
$table : string

table name

Return values
self

offset()

Set offset

public offset(int|null $offset) : self
// OFFSET 10 $Core_QueryBuilder_Select->offset(10);
Parameters
$offset : int|null

offset

Return values
self

offsetPostgreSQLSyntax()

Offset compatibility with PostgreSQL, default TRUE $param boolean $compatible

public offsetPostgreSQLSyntax(mixed $compatible) : mixed
Parameters
$compatible : mixed
Return values
mixed

open()

Open bracket in WHERE

public open() : self
Return values
self

order()

Order options

public order(string $column[, string $direction = 'ASC' ][, bool $binary = FALSE ]) : mixed
Parameters
$column : string

column

$direction : string = 'ASC'

sorting direction

$binary : bool = FALSE

binary option

Tags
see
orderBy()
Return values
mixed

orderBy()

Set order column and direction

public orderBy(string $column[, string $direction = 'ASC' ][, bool $binary = FALSE ]) : self

http://dev.mysql.com/doc/refman/5.7/en/sorting-rows.html

// ORDER BY `field1` ASC $Core_QueryBuilder_Select->orderBy('field1');

// ORDER BY field1 DESC $Core_QueryBuilder_Select->orderBy('field1', 'DESC');

// ORDER BY BINARY field1 DESC $Core_QueryBuilder_Select->orderBy('field1', 'DESC', TRUE);

// ORDER BY field2 RAND() $Core_QueryBuilder_Select->orderBy('field1', 'RAND()');

Parameters
$column : string

column

$direction : string = 'ASC'

sorting direction

$binary : bool = FALSE

binary option

Return values
self

orderByRaw()

Add raw expression into ORDER BY.

public orderByRaw(string $expr) : self

ATTENTION! Danger, you should escape the query yourself!

// ORDER BY `field1` + `field2` ASC $Core_QueryBuilder_Select->orderByRaw('`field1` + `field2` ASC');
Parameters
$expr : string

expression

Return values
self

orHaving()

Add OR and HAVING, e.g. HAVING ... OR $column $expression $value

public orHaving(string $column, string $expression, string $value) : self
// HAVING `a1` > 2 OR `a2` < 7 $Core_QueryBuilder_Select->having('a1', '>', 2)->orHaving('a2', '<', 7);
Parameters
$column : string

column

$expression : string

expression

$value : string

value

Return values
self

orWhere()

Add OR and WHERE, e.g. WHERE ... OR $column $expression $value

public orWhere(string $column[, string $expression = NULL ][, string $value = NULL ]) : self
// WHERE `a1` > 2 OR `a2` < 7 $Core_QueryBuilder_Select->where('a1', '>', 2)->orWhere('a2', '<', 7);
Parameters
$column : string

column

$expression : string = NULL

expression

$value : string = NULL

value

Return values
self

orWhereBetween()

Add OR and WHERE $column BETWEEN x AND y

public orWhereBetween(string $column, string $from, string $to) : self
// WHERE ... OR `a7` BETWEEN 1 AND 10 $Core_QueryBuilder_Select->orWhereBetween('a7', 1, 10);
Parameters
$column : string

column

$from : string
$to : string
Return values
self

orWhereColumn()

Set OR and verify two columns

public orWhereColumn(string $column1, string $expression, string $column2) : self
// WHERE ... OR `a1` = `a2` $Core_QueryBuilder_Select->orWhereColumn('a1', '=', 'a2');
Parameters
$column1 : string

first column

$expression : string

expression

$column2 : string

second column

Return values
self

orWhereIn()

Add OR and WHERE $column IN (x, y)

public orWhereIn(string $column, string $value) : self
// WHERE ... OR `a7` IN (1, 2, 'aaa') $Core_QueryBuilder_Select->orWhereIn('a7', array(1, 2, 'aaa'));
Parameters
$column : string

column

$value : string

value

Return values
self

orWhereIsNotNull()

Add OR and WHERE $column IS NOT NULL

public orWhereIsNotNull(string $column) : self
// WHERE `a1` IS NOT NULL $Core_QueryBuilder_Select->orWhereIsNotNull('a1');
Parameters
$column : string

column

Return values
self

orWhereIsNull()

Add OR and WHERE $column IS NULL

public orWhereIsNull(string $column) : self
// WHERE `a1` IS NULL OR `a2` IS NULL $Core_QueryBuilder_Select->whereIsNull('a1')->orWhereIsNull('a2');
Parameters
$column : string

column

Return values
self

orWhereNotBetween()

Add OR and WHERE $column NOT BETWEEN x AND y

public orWhereNotBetween(string $column, string $from, string $to) : self
// WHERE ... OR `a7` NOT BETWEEN 1 AND 10 $Core_QueryBuilder_Select->orWhereNotBetween('a7', 1, 10);
Parameters
$column : string

column

$from : string
$to : string
Return values
self

orWhereNotIn()

Add OR and WHERE $column NOT IN (x, y)

public orWhereNotIn(string $column, string $value) : self
// WHERE ... OR `a7` NOT IN (1, 2, 'aaa') $Core_QueryBuilder_Select->orWhereNotIn('a7', array(1, 2, 'aaa'));
Parameters
$column : string

column

$value : string

value

Return values
self

partition()

Set PARTITION

public partition(mixed $tableName, array<string|int, mixed> $partitions) : Core_QueryBuilder_Select
// FROM|JOIN `tableName` PARTITION (`p0`, `p1`) $oCore_QueryBuilder_Select = $Core_QueryBuilder_Select->from('tableName')->partition('tableName', array('p0', 'p1'));
Parameters
$tableName : mixed
$partitions : array<string|int, mixed>
Return values
Core_QueryBuilder_Select

quoteTable()

Quote columns

public quoteTable(mixed $tableName) : array<string|int, mixed>
Parameters
$tableName : mixed
Return values
array<string|int, mixed>

rightJoin()

RIGHT OUTER JOIN

public rightJoin(string $table, string $column[, string $expression = NULL ][, string $value = NULL ][, string $additionalConditions = NULL ]) : self
// RIGHT OUTER JOIN `join1` USING (`join_field2`) $Core_QueryBuilder_Select->rightJoin('join1', 'join_field2');

// RIGHT OUTER JOIN jointable.join1 ON join_field = join_field2 $Core_QueryBuilder_Select->rightJoin('jointable.join1', 'join_field', '=', 'join_field2');

Parameters
$table : string

table name

$column : string

column name

$expression : string = NULL

expression

$value : string = NULL

value

$additionalConditions : string = NULL

additional conditions

Return values
self

rightJoinFirst()

Add RIGHT OUTER JOIN first

public rightJoinFirst(string $table, string $column[, string $expression = NULL ][, string $value = NULL ][, string $additionalConditions = NULL ]) : self
Parameters
$table : string

table name

$column : string

column name

$expression : string = NULL

expression

$value : string = NULL

value

$additionalConditions : string = NULL

additional conditions

Return values
self

select()

Alias for columns()

public select() : mixed
Tags
see
columns()
Return values
mixed

selectDistinct()

Set DISTINCT and add columns for select

public selectDistinct() : self
Tags
see
columns()
Return values
self

setAnd()

Set operator as AND

public setAnd() : self
Return values
self

setDefaultOperator()

Set operator as a default operator

public setDefaultOperator() : self
Return values
self

setOperator()

Set operator as a default operator

public setOperator(string $operator) : self
Parameters
$operator : string
Return values
self

setOr()

Set operator as OR

public setOr() : self
Return values
self

sqlCalcFoundRows()

Set SQL_CALC_FOUND_ROWS

public sqlCalcFoundRows([bool $value = TRUE ]) : self
$oCore_QueryBuilder_Select = Core_QueryBuilder::select()->sqlCalcFoundRows();
Parameters
$value : bool = TRUE
Return values
self

straightJoin()

Set STRAIGHT_JOIN

public straightJoin([bool $value = TRUE ]) : self
$oCore_QueryBuilder_Select = Core_QueryBuilder::select()->straightJoin();
Parameters
$value : bool = TRUE
Return values
self

unbuffered()

Query without fetching and buffering the result rows

public unbuffered(bool $unbuffered) : self
Parameters
$unbuffered : bool
Return values
self

union()

UNION is used to combine the result from multiple SELECT statements into a single result set.

public union(Core_QueryBuilder_Select $object) : self
// (SELECT `id2`, `name2` FROM `tablename2`) // UNION // (SELECT `id`, `name` FROM `tablename` LIMIT 10 OFFSET 0) $select1 = Core_QueryBuilder::select('id', 'name')->from('tablename') ->limit(0, 10);

$select2 = Core_QueryBuilder::select('id2', 'name2')->from('tablename2') ->union($select1);

Parameters
$object : Core_QueryBuilder_Select
Return values
self

unionAll()

UNION ALL is used to combine the result from multiple SELECT statements into a single result set.

public unionAll(Core_QueryBuilder_Select $object) : self
// (SELECT `id2`, `name2` FROM `tablename2`) // UNION ALL // (SELECT `id`, `name` FROM `tablename` LIMIT 10 OFFSET 0) $select1 = Core_QueryBuilder::select('id', 'name')->from('tablename') ->limit(0, 10);

$select2 = Core_QueryBuilder::select('id2', 'name2')->from('tablename2') ->unionAll($select1);

Parameters
$object : Core_QueryBuilder_Select
Return values
self

unionLimit()

LIMIT for UNION

public unionLimit(string $arg1[, string $arg2 = NULL ]) : mixed
Parameters
$arg1 : string

offset

$arg2 : string = NULL

count

Return values
mixed

unionOffset()

Set UNION offset

public unionOffset(int $offset) : selfion
Parameters
$offset : int

offset

Return values
selfion

unionOrderBy()

ORDER BY for UNION

public unionOrderBy(string $column[, string $direction = 'ASC' ][, bool $binary = FALSE ]) : mixed

http://dev.mysql.com/doc/refman/5.7/en/union.html

Parameters
$column : string

column

$direction : string = 'ASC'

sorting direction

$binary : bool = FALSE

binary option

Return values
mixed

where()

Add WHERE

public where(string $column[, string $expression = NULL ][, string $value = NULL ]) : self
// WHERE `a1` > '2' $Core_QueryBuilder_Select->where('a1', '>', '2');

// WHERE a4 IN (17, 19, NULL, 'NULL') $Core_QueryBuilder_Select->where('a4', 'IN', array(17, 19, NULL, 'NULL'));

// WHERE a7 BETWEEN 1 AND 10 $Core_QueryBuilder_Select->where('a7', 'BETWEEN', array(1, 10));

Parameters
$column : string

column

$expression : string = NULL

expression

$value : string = NULL

value

Return values
self

whereBetween()

Add WHERE $column BETWEEN x AND y

public whereBetween(string $column, string $from, string $to) : self
// WHERE `a7` BETWEEN 1 AND 10 $Core_QueryBuilder_Select->whereBetween('a7', 1, 10);
Parameters
$column : string

column

$from : string
$to : string
Return values
self

whereColumn()

Verify two columns

public whereColumn(string $column1, string $expression, string $column2) : self
// WHERE `a1` = `a2` $Core_QueryBuilder_Select->whereColumn('a1', '=', 'a2');
Parameters
$column1 : string

first column

$expression : string

expression

$column2 : string

second column

Return values
self

whereIn()

Add WHERE $column IN (x, y)

public whereIn(string $column, string $value) : self
// WHERE `a7` IN (1, 2, 'aaa') $Core_QueryBuilder_Select->whereIn('a7', array(1, 2, 'aaa'));
Parameters
$column : string

column

$value : string

value

Return values
self

whereIsNotNull()

Add WHERE $column IS NOT NULL

public whereIsNotNull(string $column) : self
// WHERE `a2` IS NOT NULL $Core_QueryBuilder_Select->whereIsNotNull('a2');
Parameters
$column : string

column

Return values
self

whereIsNull()

Add WHERE $column IS NULL

public whereIsNull(string $column) : self
// WHERE `a1` IS NULL $Core_QueryBuilder_Select->whereIsNull('a1');
Parameters
$column : string

column

Return values
self

whereNotBetween()

Add WHERE $column NOT BETWEEN x AND y

public whereNotBetween(string $column, string $from, string $to) : self
// WHERE `a7` NOT BETWEEN 1 AND 10 $Core_QueryBuilder_Select->whereNotBetween('a7', 1, 10);
Parameters
$column : string

column

$from : string
$to : string
Return values
self

whereNotIn()

Add WHERE $column NOT IN (x, y)

public whereNotIn(string $column, string $value) : self
// WHERE `a7` NOT IN (1, 2, 'aaa') $Core_QueryBuilder_Select->whereNotIn('a7', array(1, 2, 'aaa'));
Parameters
$column : string

column

$value : string

value

Return values
self

whereRaw()

Add raw expression into WHERE.

public whereRaw(string $expr) : self

ATTENTION! Danger, you should escape the query yourself!

// WHERE `a1` > 2 $Core_QueryBuilder_Select->whereRaw("`a1` > 2");
Parameters
$expr : string

expression

Return values
self

_buildExpression()

Build WHERE or HAVING expression

protected _buildExpression(array<string|int, mixed> $aConditions) : string
Parameters
$aConditions : array<string|int, mixed>

list of conditions

Tags
see
_buildWhere()
Return values
string

The SQL query

_buildIndexHint()

Build INDEX expression

protected _buildIndexHint(array<string|int, mixed> $aTableIndexHints) : string
Parameters
$aTableIndexHints : array<string|int, mixed>
Return values
string

The SQL query

_buildJoin()

Build JOIN expression

protected _buildJoin(array<string|int, mixed> $aJoins) : string
Parameters
$aJoins : array<string|int, mixed>
Return values
string

The SQL query

_buildOrderBy()

Build ORDER BY expression

protected _buildOrderBy(array<string|int, mixed> $aOrderBy) : string
Parameters
$aOrderBy : array<string|int, mixed>
Return values
string

The SQL query

_buildWhere()

Build expression for one condition

protected _buildWhere(string $column, string $expression, string $value) : string
Parameters
$column : string

column

$expression : string

expression

$value : string

value

Tags
see
_buildExpression()
Return values
string

The SQL query

_isObjectSelect()

Is $object Core_QueryBuilder_Select

protected _isObjectSelect( $object) : bool
Parameters
$object :
Return values
bool

_join()

http://dev.mysql.com/doc/refman/5.7/en/join.html

protected _join(string $type, string $table[, string|null $column = NULL ][, string|null $expression = NULL ][, string|null $value = NULL ][, string|null $additionalConditions = NULL ][, mixed $mode = NULL ]) : self
Parameters
$type : string

join type

$table : string

table name

$column : string|null = NULL

column name

$expression : string|null = NULL

expression

$value : string|null = NULL

value

$additionalConditions : string|null = NULL

additional conditions

$mode : mixed = NULL
Return values
self

_quoteColumns()

Quote columns

protected _quoteColumns(array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
Return values
array<string|int, mixed>

_quoteTables()

Quote columns

protected _quoteTables(array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
Return values
array<string|int, mixed>

_quoteValues()

Quote arary of values

protected _quoteValues(array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
Return values
array<string|int, mixed>

Search results