Select
extends Statement
in package
uses
Explain, Join, GroupBy, Having, OrderBy
Class Select.
Tags
Table of Contents
Constants
- EXP_EXTENDED : string = 'EXTENDED'
- EXP_FIELDS_ENCLOSED_BY : string = 'ENCLOSED BY'
- Clause to set the enclosure character of the fields. Default is ".
- EXP_FIELDS_ESCAPED_BY : string = 'ESCAPED BY'
- EXP_FIELDS_OPTIONALLY_ENCLOSED_BY : string = 'OPTIONALLY ENCLOSED BY'
- EXP_FIELDS_TERMINATED_BY : string = 'TERMINATED BY'
- Clause to set the character of separation between fields. Default is \t.
- EXP_FORMAT_JSON : string = 'FORMAT=JSON'
- EXP_LINES_STARTING_BY : string = 'STARTING BY'
- EXP_LINES_TERMINATED_BY : string = 'TERMINATED BY'
- Clause to set the file End-Of-Line character. Default is \n.
- EXP_PARTITIONS : string = 'PARTITIONS'
- https://mariadb.com/kb/en/partition-pruning-and-selection/.
- OPT_ALL : string = 'ALL'
- Option to retrieve identical rows.
- OPT_DISTINCT : string = 'DISTINCT'
- Option to not retrieve identical rows. Remove duplicates from the result set.
- OPT_DISTINCTROW : string = 'DISTINCTROW'
- Alias of OPT_DISTINCT.
- OPT_HIGH_PRIORITY : string = 'HIGH_PRIORITY'
- If the table is locked, HIGH_PRIORITY will be executed as soon as the lock is released, even if other statements are queued.
- OPT_SQL_BIG_RESULT : string = 'SQL_BIG_RESULT'
- Forces the optimizer to avoid usage of a temporary table.
- OPT_SQL_BUFFER_RESULT : string = 'SQL_BUFFER_RESULT'
- Forces the optimizer to use a temporary table to process the result.
- OPT_SQL_CACHE : string = 'SQL_CACHE'
- If the query_cache_type system variable is set to 2 or DEMAND, and the current statement is cacheable, SQL_CACHE causes the query to be cached.
- OPT_SQL_CALC_FOUND_ROWS : string = 'SQL_CALC_FOUND_ROWS'
- SQL_CALC_FOUND_ROWS is only applied when using the LIMIT clause. If this option is used, MariaDB will count how many rows would match the query, without the LIMIT clause.
- OPT_SQL_NO_CACHE : string = 'SQL_NO_CACHE'
- If the query_cache_type system variable is set to 2 or DEMAND, and the current statement is cacheable, SQL_NO_CACHE causes the query not to be cached.
- OPT_SQL_SMALL_RESULT : string = 'SQL_SMALL_RESULT'
- Forces the optimizer to use a temporary table.
- OPT_STRAIGHT_JOIN : string = 'STRAIGHT_JOIN'
- Applicable to the JOIN queries. Tells the optimizer that the tables must be read in the order they appear.
Properties
Methods
- __construct() : mixed
- Statement constructor.
- __toString() : string
- columns() : static
- Alias of the expressions method.
- crossJoin() : static
- Adds a JOIN clause with "CROSS JOIN $table".
- crossJoinOn() : static
- Adds a JOIN clause with "CROSS JOIN $table ON $conditional".
- crossJoinUsing() : static
- Adds a JOIN clause with "CROSS JOIN $table USING ...$columns".
- explain() : array<int, Explain>
- EXPLAIN provides information about statements.
- expressions() : static
- Set expressions.
- from() : static
- Sets the FROM clause.
- groupBy() : static
- Appends columns to the GROUP BY clause.
- groupByAsc() : static
- Appends columns with the ASC direction to the GROUP BY clause.
- groupByDesc() : static
- Appends columns with the DESC direction to the GROUP BY clause.
- having() : static
- Appends an "AND $column $operator ...$values" condition in the HAVING clause.
- havingBetween() : static
- Appends an "AND $column BETWEEN $min AND $max" condition in the HAVING clause.
- havingEqual() : static
- Appends an "AND $column = $value" condition in the HAVING clause.
- havingGreaterThan() : static
- Appends an "AND $column > $value" condition in the HAVING clause.
- havingGreaterThanOrEqual() : static
- Appends an "AND $column >= $value" condition in the HAVING clause.
- havingIn() : static
- Appends an "AND $column IN (...$values)" condition in the HAVING clause.
- havingIsNotNull() : static
- Appends an "AND $column IS NOT NULL" condition in the HAVING clause.
- havingIsNull() : static
- Appends an "AND $column IS NULL" condition in the HAVING clause.
- havingLessThan() : static
- Appends an "AND $column < $value" condition in the HAVING clause.
- havingLessThanOrEqual() : static
- Appends an "AND $column <= $value" condition in the HAVING clause.
- havingLike() : static
- Appends an "AND $column LIKE $value" condition in the HAVING clause.
- havingNotBetween() : static
- Appends an "AND $column NOT BETWEEN $min AND $max" condition in the HAVING clause.
- havingNotEqual() : static
- Appends an "AND $column != $value" condition in the HAVING clause.
- havingNotIn() : static
- Appends an "AND $column NOT IN (...$values)" condition in the HAVING clause.
- havingNotLike() : static
- Appends an "AND $column NOT LIKE" $value condition.
- havingNullSafeEqual() : static
- Appends an "AND $column <=> $value" condition in the HAVING clause.
- innerJoinOn() : static
- Adds a JOIN clause with "INNER JOIN $table ON $conditional".
- innerJoinUsing() : static
- Adds a JOIN clause with "INNER JOIN $table USING ...$columns".
- intoDumpfile() : static
- intoOutfile() : static
- Exports the result to an external file.
- join() : static
- Adds a JOIN clause with "$type JOIN $table $clause $conditional".
- joinOn() : static
- Adds a JOIN clause with "JOIN $table ON $conditional".
- joinUsing() : static
- Adds a JOIN clause with "JOIN $table USING ...$columns".
- leftJoinOn() : static
- Adds a JOIN clause with "LEFT JOIN $table ON $conditional".
- leftJoinUsing() : static
- Adds a JOIN clause with "LEFT JOIN $table USING ...$columns".
- leftOuterJoinOn() : static
- Adds a JOIN clause with "LEFT OUTER JOIN $table ON $conditional".
- leftOuterJoinUsing() : static
- Adds a JOIN clause with "LEFT OUTER JOIN $table USING ...$columns".
- limit() : static
- Sets the LIMIT clause.
- lockForUpdate() : static
- lockInShareMode() : static
- naturalJoin() : static
- Adds a JOIN clause with "NATURAL JOIN $table".
- naturalLeftJoin() : static
- Adds a JOIN clause with "NATURAL LEFT JOIN $table".
- naturalLeftOuterJoin() : static
- Adds a JOIN clause with "NATURAL LEFT OUTER JOIN $table".
- naturalRightJoin() : static
- Adds a JOIN clause with "NATURAL RIGHT JOIN $table".
- naturalRightOuterJoin() : static
- Adds a JOIN clause with "NATURAL RIGHT OUTER JOIN $table".
- options() : static
- Sets the statement options.
- orderBy() : static
- Appends columns to the ORDER BY clause.
- orderByAsc() : static
- Appends columns with the ASC direction to the ORDER BY clause.
- orderByDesc() : static
- Appends columns with the DESC direction to the ORDER BY clause.
- orHaving() : static
- Appends a "OR $column $operator ...$values" condition in the HAVING clause.
- orHavingBetween() : static
- Appends a "OR $column BETWEEN $min AND $max" condition in the HAVING clause.
- orHavingEqual() : static
- Appends a "OR $column = $value" condition in the HAVING clause.
- orHavingGreaterThan() : static
- Appends a "OR $column > $value" condition in the HAVING clause.
- orHavingGreaterThanOrEqual() : static
- Appends a "OR $column >= $value" condition in the HAVING clause.
- orHavingIn() : static
- Appends a "OR $column IN (...$values)" condition in the HAVING clause.
- orHavingIsNotNull() : static
- Appends a "OR $column IS NOT NULL" condition in the HAVING clause.
- orHavingIsNull() : static
- Appends a "OR $column IS NULL" condition in the HAVING clause.
- orHavingLessThan() : static
- Appends a "OR $column < $value" condition in the HAVING clause.
- orHavingLessThanOrEqual() : static
- Appends a "OR $column <= $value" condition in the HAVING clause.
- orHavingLike() : static
- Appends a "OR $column LIKE $value" condition in the HAVING clause.
- orHavingNotBetween() : static
- Appends a "OR $column NOT BETWEEN $min AND $max" condition in the HAVING clause.
- orHavingNotEqual() : static
- Appends a "OR $column != $value" condition in the HAVING clause.
- orHavingNotIn() : static
- Appends a "OR $column NOT IN (...$values)" condition in the HAVING clause.
- orHavingNotLike() : static
- Appends a "OR $column NOT LIKE $value" condition in the HAVING clause.
- orHavingNullSafeEqual() : static
- Appends a "OR $column <=> $value" condition in the HAVING clause.
- procedure() : static
- reset() : static
- Resets SQL clauses and parts.
- rightJoinOn() : static
- Adds a JOIN clause with "RIGHT JOIN $table ON $conditional".
- rightJoinUsing() : static
- Adds a JOIN clause with "RIGHT JOIN $table USING ...$columns".
- rightOuterJoinOn() : static
- Adds a JOIN clause with "RIGHT OUTER JOIN $table ON $conditional".
- rightOuterJoinUsing() : static
- Adds a JOIN clause with "RIGHT OUTER JOIN $table USING ...$columns".
- run() : Result
- Runs the SELECT statement.
- runUnbuffered() : Result
- Runs the SELECT statement unbuffered.
- sql() : string
- Renders the SELECT statement.
- hasFrom() : bool
- Tells if the FROM clause was set.
- hasOptions() : bool
- Tells if the statement has options set.
- renderAliasedIdentifier() : string
- Renders a column part with an optional alias name, AS clause.
- renderAssignment() : string
- Renders an assignment part.
- renderExpressions() : string|null
- renderFrom() : string|null
- Renders the FROM clause.
- renderGroupBy() : string|null
- Renders the GROUP BY clause.
- renderHaving() : string|null
- Renders the full HAVING clause.
- renderIdentifier() : string
- Renders a column part.
- renderIntoDumpfile() : string|null
- renderIntoOutfile() : string|null
- renderJoin() : string|null
- Renders the JOIN clause.
- renderLimit() : string|null
- Renders the LIMIT clause.
- renderLock() : string|null
- renderOptions() : string|null
- renderOrderBy() : string|null
- Renders the ORDER BY clause.
- renderProcedure() : string|null
- renderValue() : float|int|string
- Renders a subquery or quote a value.
- setLimit() : static
- Sets the LIMIT clause.
- subquery() : string
- Returns an SQL part between parentheses.
Constants
EXP_EXTENDED
public
string
EXP_EXTENDED
= 'EXTENDED'
Tags
EXP_FIELDS_ENCLOSED_BY
Clause to set the enclosure character of the fields. Default is ".
public
string
EXP_FIELDS_ENCLOSED_BY
= 'ENCLOSED BY'
Tags
EXP_FIELDS_ESCAPED_BY
public
string
EXP_FIELDS_ESCAPED_BY
= 'ESCAPED BY'
Tags
EXP_FIELDS_OPTIONALLY_ENCLOSED_BY
public
string
EXP_FIELDS_OPTIONALLY_ENCLOSED_BY
= 'OPTIONALLY ENCLOSED BY'
Tags
EXP_FIELDS_TERMINATED_BY
Clause to set the character of separation between fields. Default is \t.
public
string
EXP_FIELDS_TERMINATED_BY
= 'TERMINATED BY'
Tags
EXP_FORMAT_JSON
public
string
EXP_FORMAT_JSON
= 'FORMAT=JSON'
Tags
EXP_LINES_STARTING_BY
public
string
EXP_LINES_STARTING_BY
= 'STARTING BY'
Tags
EXP_LINES_TERMINATED_BY
Clause to set the file End-Of-Line character. Default is \n.
public
string
EXP_LINES_TERMINATED_BY
= 'TERMINATED BY'
Tags
EXP_PARTITIONS
https://mariadb.com/kb/en/partition-pruning-and-selection/.
public
string
EXP_PARTITIONS
= 'PARTITIONS'
OPT_ALL
Option to retrieve identical rows.
public
string
OPT_ALL
= 'ALL'
Tags
OPT_DISTINCT
Option to not retrieve identical rows. Remove duplicates from the result set.
public
string
OPT_DISTINCT
= 'DISTINCT'
Tags
OPT_DISTINCTROW
Alias of OPT_DISTINCT.
public
string
OPT_DISTINCTROW
= 'DISTINCTROW'
Tags
OPT_HIGH_PRIORITY
If the table is locked, HIGH_PRIORITY will be executed as soon as the lock is released, even if other statements are queued.
public
string
OPT_HIGH_PRIORITY
= 'HIGH_PRIORITY'
Only supports table-level locking (MyISAM, MEMORY, MERGE).
Tags
OPT_SQL_BIG_RESULT
Forces the optimizer to avoid usage of a temporary table.
public
string
OPT_SQL_BIG_RESULT
= 'SQL_BIG_RESULT'
Tags
OPT_SQL_BUFFER_RESULT
Forces the optimizer to use a temporary table to process the result.
public
string
OPT_SQL_BUFFER_RESULT
= 'SQL_BUFFER_RESULT'
This is useful to free locks as soon as possible.
Tags
OPT_SQL_CACHE
If the query_cache_type system variable is set to 2 or DEMAND, and the current statement is cacheable, SQL_CACHE causes the query to be cached.
public
string
OPT_SQL_CACHE
= 'SQL_CACHE'
Tags
OPT_SQL_CALC_FOUND_ROWS
SQL_CALC_FOUND_ROWS is only applied when using the LIMIT clause. If this option is used, MariaDB will count how many rows would match the query, without the LIMIT clause.
public
string
OPT_SQL_CALC_FOUND_ROWS
= 'SQL_CALC_FOUND_ROWS'
That number can be retrieved in the next query, using FOUND_ROWS().
Tags
OPT_SQL_NO_CACHE
If the query_cache_type system variable is set to 2 or DEMAND, and the current statement is cacheable, SQL_NO_CACHE causes the query not to be cached.
public
string
OPT_SQL_NO_CACHE
= 'SQL_NO_CACHE'
Tags
OPT_SQL_SMALL_RESULT
Forces the optimizer to use a temporary table.
public
string
OPT_SQL_SMALL_RESULT
= 'SQL_SMALL_RESULT'
Tags
OPT_STRAIGHT_JOIN
Applicable to the JOIN queries. Tells the optimizer that the tables must be read in the order they appear.
public
string
OPT_STRAIGHT_JOIN
= 'STRAIGHT_JOIN'
For const and system table this option is sometimes ignored.
Tags
Properties
$database
protected
Database
$database
$sql
SQL clauses and parts.
protected
array<string, mixed>
$sql
= []
Methods
__construct()
Statement constructor.
public
__construct(Database $database) : mixed
Parameters
- $database : Database
__toString()
public
__toString() : string
Return values
stringcolumns()
Alias of the expressions method.
public
columns(Closure|array<string, Closure|string>|string $expression, Closure|array<string, Closure|string>|string ...$expressions) : static
Parameters
- $expression : Closure|array<string, Closure|string>|string
- $expressions : Closure|array<string, Closure|string>|string
Return values
staticcrossJoin()
Adds a JOIN clause with "CROSS JOIN $table".
public
crossJoin(Closure|array<string, Closure|string>|string $table) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
Return values
staticcrossJoinOn()
Adds a JOIN clause with "CROSS JOIN $table ON $conditional".
public
crossJoinOn(Closure|array<string, Closure|string>|string $table, Closure $conditional) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
- $conditional : Closure
-
Conditional expression
Return values
staticcrossJoinUsing()
Adds a JOIN clause with "CROSS JOIN $table USING ...$columns".
public
crossJoinUsing(Closure|array<string, Closure|string>|string $table, Closure|string ...$columns) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
- $columns : Closure|string
-
Columns list
Return values
staticexplain()
EXPLAIN provides information about statements.
public
explain([string|null $option = null ]) : array<int, Explain>
Parameters
- $option : string|null = null
Tags
Return values
array<int, Explain>expressions()
Set expressions.
public
expressions(Closure|array<string, Closure|string>|string $expression, Closure|array<string, Closure|string>|string ...$expressions) : static
Generally used with the FROM clause as column names.
Parameters
- $expression : Closure|array<string, Closure|string>|string
- $expressions : Closure|array<string, Closure|string>|string
Tags
Return values
staticfrom()
Sets the FROM clause.
public
from(Closure|array<string, Closure|string>|string $reference, Closure|array<string, Closure|string>|string ...$references) : static
Parameters
- $reference : Closure|array<string, Closure|string>|string
-
Table reference
- $references : Closure|array<string, Closure|string>|string
-
Table references
Tags
Return values
staticgroupBy()
Appends columns to the GROUP BY clause.
public
groupBy(Closure|string $column, Closure|string ...$columns) : static
Parameters
- $column : Closure|string
-
The column name or a subquery
- $columns : Closure|string
-
Extra column names and/or subqueries
Return values
staticgroupByAsc()
Appends columns with the ASC direction to the GROUP BY clause.
public
groupByAsc(Closure|string $column, Closure|string ...$columns) : static
Parameters
- $column : Closure|string
-
The column name or a subquery
- $columns : Closure|string
-
Extra column names and/or subqueries
Return values
staticgroupByDesc()
Appends columns with the DESC direction to the GROUP BY clause.
public
groupByDesc(Closure|string $column, Closure|string ...$columns) : static
Parameters
- $column : Closure|string
-
The column name or a subquery
- $columns : Closure|string
-
Extra column names and/or subqueries
Return values
statichaving()
Appends an "AND $column $operator ...$values" condition in the HAVING clause.
public
having(Closure|string $column, string $operator, Closure|float|int|string|null ...$values) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $operator : string
- $values : Closure|float|int|string|null
Return values
statichavingBetween()
Appends an "AND $column BETWEEN $min AND $max" condition in the HAVING clause.
public
havingBetween(Closure|string $column, Closure|float|int|string|null $min, Closure|float|int|string|null $max) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $min : Closure|float|int|string|null
- $max : Closure|float|int|string|null
Tags
Return values
statichavingEqual()
Appends an "AND $column = $value" condition in the HAVING clause.
public
havingEqual(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
statichavingGreaterThan()
Appends an "AND $column > $value" condition in the HAVING clause.
public
havingGreaterThan(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
statichavingGreaterThanOrEqual()
Appends an "AND $column >= $value" condition in the HAVING clause.
public
havingGreaterThanOrEqual(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
statichavingIn()
Appends an "AND $column IN (...$values)" condition in the HAVING clause.
public
havingIn(Closure|string $column, Closure|float|int|string|null $value, Closure|float|int|string|null ...$values) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
- $values : Closure|float|int|string|null
Tags
Return values
statichavingIsNotNull()
Appends an "AND $column IS NOT NULL" condition in the HAVING clause.
public
havingIsNotNull(Closure|string $column) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
Tags
Return values
statichavingIsNull()
Appends an "AND $column IS NULL" condition in the HAVING clause.
public
havingIsNull(Closure|string $column) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
Tags
Return values
statichavingLessThan()
Appends an "AND $column < $value" condition in the HAVING clause.
public
havingLessThan(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
statichavingLessThanOrEqual()
Appends an "AND $column <= $value" condition in the HAVING clause.
public
havingLessThanOrEqual(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
statichavingLike()
Appends an "AND $column LIKE $value" condition in the HAVING clause.
public
havingLike(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
statichavingNotBetween()
Appends an "AND $column NOT BETWEEN $min AND $max" condition in the HAVING clause.
public
havingNotBetween(Closure|string $column, Closure|float|int|string|null $min, Closure|float|int|string|null $max) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $min : Closure|float|int|string|null
- $max : Closure|float|int|string|null
Tags
Return values
statichavingNotEqual()
Appends an "AND $column != $value" condition in the HAVING clause.
public
havingNotEqual(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
statichavingNotIn()
Appends an "AND $column NOT IN (...$values)" condition in the HAVING clause.
public
havingNotIn(Closure|string $column, Closure|float|int|string|null $value, Closure|float|int|string|null ...$values) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
- $values : Closure|float|int|string|null
Tags
Return values
statichavingNotLike()
Appends an "AND $column NOT LIKE" $value condition.
public
havingNotLike(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
statichavingNullSafeEqual()
Appends an "AND $column <=> $value" condition in the HAVING clause.
public
havingNullSafeEqual(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
staticinnerJoinOn()
Adds a JOIN clause with "INNER JOIN $table ON $conditional".
public
innerJoinOn(Closure|array<string, Closure|string>|string $table, Closure $conditional) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
- $conditional : Closure
-
Conditional expression
Return values
staticinnerJoinUsing()
Adds a JOIN clause with "INNER JOIN $table USING ...$columns".
public
innerJoinUsing(Closure|array<string, Closure|string>|string $table, Closure|string ...$columns) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
- $columns : Closure|string
-
Columns list
Return values
staticintoDumpfile()
public
intoDumpfile(string $filepath, string ...$variables) : static
Parameters
- $filepath : string
- $variables : string
Tags
Return values
staticintoOutfile()
Exports the result to an external file.
public
intoOutfile(string $filename[, string|null $charset = null ][, array<string, string> $fieldsOptions = [] ][, array<string, string> $linesOptions = [] ]) : static
Parameters
- $filename : string
- $charset : string|null = null
- $fieldsOptions : array<string, string> = []
-
Each key must be one of the EXP_FIELDS_* constants
- $linesOptions : array<string, string> = []
-
Each key must be one of the EXP_LINES_* constants
Tags
Return values
staticjoin()
Adds a JOIN clause with "$type JOIN $table $clause $conditional".
public
join(Closure|array<string, Closure|string>|string $table[, string $type = '' ][, string|null $clause = null ][, Closure|array<int, Closure|string>|null $conditional = null ]) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
- $type : string = ''
-
JOIN type. One of:
CROSS,INNER,LEFT,LEFT OUTER,RIGHT,RIGHT OUTER,NATURAL,NATURAL LEFT,NATURAL LEFT OUTER,NATURAL RIGHT,NATURAL RIGHT OUTERor empty (same asINNER) - $clause : string|null = null
-
Condition clause. Null if it has a NATURAL type, otherwise
ONorUSING - $conditional : Closure|array<int, Closure|string>|null = null
-
A conditional expression as Closure or the columns list as array
Return values
staticjoinOn()
Adds a JOIN clause with "JOIN $table ON $conditional".
public
joinOn(Closure|array<string, Closure|string>|string $table, Closure $conditional) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
- $conditional : Closure
-
Conditional expression
Return values
staticjoinUsing()
Adds a JOIN clause with "JOIN $table USING ...$columns".
public
joinUsing(Closure|array<string, Closure|string>|string $table, Closure|string ...$columns) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
- $columns : Closure|string
-
Columns list
Return values
staticleftJoinOn()
Adds a JOIN clause with "LEFT JOIN $table ON $conditional".
public
leftJoinOn(Closure|array<string, Closure|string>|string $table, Closure $conditional) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
- $conditional : Closure
-
Conditional expression
Return values
staticleftJoinUsing()
Adds a JOIN clause with "LEFT JOIN $table USING ...$columns".
public
leftJoinUsing(Closure|array<string, Closure|string>|string $table, Closure|string ...$columns) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
- $columns : Closure|string
-
Columns list
Return values
staticleftOuterJoinOn()
Adds a JOIN clause with "LEFT OUTER JOIN $table ON $conditional".
public
leftOuterJoinOn(Closure|array<string, Closure|string>|string $table, Closure $conditional) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
- $conditional : Closure
-
Conditional expression
Return values
staticleftOuterJoinUsing()
Adds a JOIN clause with "LEFT OUTER JOIN $table USING ...$columns".
public
leftOuterJoinUsing(Closure|array<string, Closure|string>|string $table, Closure|string ...$columns) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
- $columns : Closure|string
-
Columns list
Return values
staticlimit()
Sets the LIMIT clause.
public
limit(int $limit[, int|null $offset = null ]) : static
Parameters
- $limit : int
- $offset : int|null = null
Tags
Return values
staticlockForUpdate()
public
lockForUpdate([int|null $wait = null ]) : static
Parameters
- $wait : int|null = null
Tags
Return values
staticlockInShareMode()
public
lockInShareMode([int|null $wait = null ]) : static
Parameters
- $wait : int|null = null
Tags
Return values
staticnaturalJoin()
Adds a JOIN clause with "NATURAL JOIN $table".
public
naturalJoin(Closure|array<string, Closure|string>|string $table) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
Return values
staticnaturalLeftJoin()
Adds a JOIN clause with "NATURAL LEFT JOIN $table".
public
naturalLeftJoin(Closure|array<string, Closure|string>|string $table) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
Return values
staticnaturalLeftOuterJoin()
Adds a JOIN clause with "NATURAL LEFT OUTER JOIN $table".
public
naturalLeftOuterJoin(Closure|array<string, Closure|string>|string $table) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
Return values
staticnaturalRightJoin()
Adds a JOIN clause with "NATURAL RIGHT JOIN $table".
public
naturalRightJoin(Closure|array<string, Closure|string>|string $table) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
Return values
staticnaturalRightOuterJoin()
Adds a JOIN clause with "NATURAL RIGHT OUTER JOIN $table".
public
naturalRightOuterJoin(Closure|array<string, Closure|string>|string $table) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
Return values
staticoptions()
Sets the statement options.
public
options(string $option, string ...$options) : static
Parameters
- $option : string
-
One of the OPT_* constants
- $options : string
-
Each option value must be one of the OPT_* constants
Return values
staticorderBy()
Appends columns to the ORDER BY clause.
public
orderBy(Closure|string $column, Closure|string ...$columns) : static
Parameters
- $column : Closure|string
-
The column name or a subquery
- $columns : Closure|string
-
Extra column names and/or subqueries
Return values
staticorderByAsc()
Appends columns with the ASC direction to the ORDER BY clause.
public
orderByAsc(Closure|string $column, Closure|string ...$columns) : static
Parameters
- $column : Closure|string
-
The column name or a subquery
- $columns : Closure|string
-
Extra column names and/or subqueries
Return values
staticorderByDesc()
Appends columns with the DESC direction to the ORDER BY clause.
public
orderByDesc(Closure|string $column, Closure|string ...$columns) : static
Parameters
- $column : Closure|string
-
The column name or a subquery
- $columns : Closure|string
-
Extra column names and/or subqueries
Return values
staticorHaving()
Appends a "OR $column $operator ...$values" condition in the HAVING clause.
public
orHaving(Closure|string $column, string $operator, Closure|float|int|string|null ...$values) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $operator : string
- $values : Closure|float|int|string|null
Return values
staticorHavingBetween()
Appends a "OR $column BETWEEN $min AND $max" condition in the HAVING clause.
public
orHavingBetween(Closure|string $column, Closure|float|int|string|null $min, Closure|float|int|string|null $max) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $min : Closure|float|int|string|null
- $max : Closure|float|int|string|null
Tags
Return values
staticorHavingEqual()
Appends a "OR $column = $value" condition in the HAVING clause.
public
orHavingEqual(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
staticorHavingGreaterThan()
Appends a "OR $column > $value" condition in the HAVING clause.
public
orHavingGreaterThan(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
staticorHavingGreaterThanOrEqual()
Appends a "OR $column >= $value" condition in the HAVING clause.
public
orHavingGreaterThanOrEqual(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
staticorHavingIn()
Appends a "OR $column IN (...$values)" condition in the HAVING clause.
public
orHavingIn(Closure|string $column, Closure|float|int|string|null $value, Closure|float|int|string|null ...$values) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
- $values : Closure|float|int|string|null
Tags
Return values
staticorHavingIsNotNull()
Appends a "OR $column IS NOT NULL" condition in the HAVING clause.
public
orHavingIsNotNull(Closure|string $column) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
Tags
Return values
staticorHavingIsNull()
Appends a "OR $column IS NULL" condition in the HAVING clause.
public
orHavingIsNull(Closure|string $column) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
Tags
Return values
staticorHavingLessThan()
Appends a "OR $column < $value" condition in the HAVING clause.
public
orHavingLessThan(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
staticorHavingLessThanOrEqual()
Appends a "OR $column <= $value" condition in the HAVING clause.
public
orHavingLessThanOrEqual(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
staticorHavingLike()
Appends a "OR $column LIKE $value" condition in the HAVING clause.
public
orHavingLike(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
staticorHavingNotBetween()
Appends a "OR $column NOT BETWEEN $min AND $max" condition in the HAVING clause.
public
orHavingNotBetween(Closure|string $column, Closure|float|int|string|null $min, Closure|float|int|string|null $max) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $min : Closure|float|int|string|null
- $max : Closure|float|int|string|null
Tags
Return values
staticorHavingNotEqual()
Appends a "OR $column != $value" condition in the HAVING clause.
public
orHavingNotEqual(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
staticorHavingNotIn()
Appends a "OR $column NOT IN (...$values)" condition in the HAVING clause.
public
orHavingNotIn(Closure|string $column, Closure|float|int|string|null $value, Closure|float|int|string|null ...$values) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
- $values : Closure|float|int|string|null
Tags
Return values
staticorHavingNotLike()
Appends a "OR $column NOT LIKE $value" condition in the HAVING clause.
public
orHavingNotLike(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
staticorHavingNullSafeEqual()
Appends a "OR $column <=> $value" condition in the HAVING clause.
public
orHavingNullSafeEqual(Closure|string $column, Closure|float|int|string|null $value) : static
Parameters
- $column : Closure|string
-
Closure for a subquery or a string with the column name
- $value : Closure|float|int|string|null
Tags
Return values
staticprocedure()
public
procedure(string $name, bool|float|int|string|null ...$arguments) : static
Parameters
- $name : string
- $arguments : bool|float|int|string|null
Tags
Return values
staticreset()
Resets SQL clauses and parts.
public
reset([string|null $sql = null ]) : static
Parameters
- $sql : string|null = null
-
A part name or null to reset all
Tags
Return values
staticrightJoinOn()
Adds a JOIN clause with "RIGHT JOIN $table ON $conditional".
public
rightJoinOn(Closure|array<string, Closure|string>|string $table, Closure $conditional) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
- $conditional : Closure
-
Conditional expression
Return values
staticrightJoinUsing()
Adds a JOIN clause with "RIGHT JOIN $table USING ...$columns".
public
rightJoinUsing(Closure|array<string, Closure|string>|string $table, Closure|string ...$columns) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
- $columns : Closure|string
-
Columns list
Return values
staticrightOuterJoinOn()
Adds a JOIN clause with "RIGHT OUTER JOIN $table ON $conditional".
public
rightOuterJoinOn(Closure|array<string, Closure|string>|string $table, Closure $conditional) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
- $conditional : Closure
-
Conditional expression
Return values
staticrightOuterJoinUsing()
Adds a JOIN clause with "RIGHT OUTER JOIN $table USING ...$columns".
public
rightOuterJoinUsing(Closure|array<string, Closure|string>|string $table, Closure|string ...$columns) : static
Parameters
- $table : Closure|array<string, Closure|string>|string
-
Table factor
- $columns : Closure|string
-
Columns list
Return values
staticrun()
Runs the SELECT statement.
public
run() : Result
Return values
ResultrunUnbuffered()
Runs the SELECT statement unbuffered.
public
runUnbuffered() : Result
Return values
Resultsql()
Renders the SELECT statement.
public
sql() : string
Return values
stringhasFrom()
Tells if the FROM clause was set.
protected
hasFrom([string|null $clause = null ]) : bool
Parameters
- $clause : string|null = null
-
A clause where FROM is required
Tags
Return values
bool —True if it has FROM, otherwise false
hasOptions()
Tells if the statement has options set.
protected
hasOptions() : bool
Return values
boolrenderAliasedIdentifier()
Renders a column part with an optional alias name, AS clause.
protected
renderAliasedIdentifier(Closure|array<string, Closure|string>|string $column) : string
Parameters
- $column : Closure|array<string, Closure|string>|string
-
The column name, a subquery or an array where the index is the alias and the value is the column/subquery
Return values
stringrenderAssignment()
Renders an assignment part.
protected
renderAssignment(string $identifier, Closure|float|int|string|null $expression) : string
Parameters
- $identifier : string
-
Identifier/column name
- $expression : Closure|float|int|string|null
-
Expression/value
Tags
Return values
stringrenderExpressions()
protected
renderExpressions() : string|null
Return values
string|nullrenderFrom()
Renders the FROM clause.
protected
renderFrom() : string|null
Return values
string|null —The FROM clause or null if it was not set
renderGroupBy()
Renders the GROUP BY clause.
protected
renderGroupBy() : string|null
Return values
string|null —The GROUP BY clause or null if it was not set
renderHaving()
Renders the full HAVING clause.
protected
renderHaving() : string|null
Return values
string|null —The full clause or null if has not a clause
renderIdentifier()
Renders a column part.
protected
renderIdentifier(Closure|string $column) : string
Parameters
- $column : Closure|string
-
The column name or a subquery
Return values
stringrenderIntoDumpfile()
protected
renderIntoDumpfile() : string|null
Return values
string|nullrenderIntoOutfile()
protected
renderIntoOutfile() : string|null
Return values
string|nullrenderJoin()
Renders the JOIN clause.
protected
renderJoin() : string|null
Return values
string|null —The JOIN clause or null if it was not set
renderLimit()
Renders the LIMIT clause.
protected
renderLimit() : string|null
Return values
string|nullrenderLock()
protected
renderLock() : string|null
Return values
string|nullrenderOptions()
protected
renderOptions() : string|null
Return values
string|nullrenderOrderBy()
Renders the ORDER BY clause.
protected
renderOrderBy() : string|null
Return values
string|null —The ORDER BY clause or null if it was not set
renderProcedure()
protected
renderProcedure() : string|null
Return values
string|nullrenderValue()
Renders a subquery or quote a value.
protected
renderValue(Closure|float|int|string|null $value) : float|int|string
Parameters
- $value : Closure|float|int|string|null
-
A Closure for subquery, other types to quote
Return values
float|int|stringsetLimit()
Sets the LIMIT clause.
protected
setLimit(int $limit[, int|null $offset = null ]) : static
Parameters
- $limit : int
- $offset : int|null = null
Tags
Return values
staticsubquery()
Returns an SQL part between parentheses.
protected
subquery(Closure $subquery) : string
Parameters
- $subquery : Closure
-
A Closure having the current Manipulation instance as first argument. The returned value must be scalar