tflori/orm

just another orm...

View the Project on GitHub tflori/orm

Build Status Test Coverage Maintainability Latest Stable Version Total Downloads

» API Reference » ORM\QueryBuilder\QueryBuilderInterface

ORM\QueryBuilder\QueryBuilderInterface

Table of Contents

Abstract

Extends: ORM\QueryBuilder\ParenthesisInterface

Interface QueryBuilderInterface

Constants

Name Value
DIRECTION_ASCENDING 'ASC'
DIRECTION_DESCENDING 'DESC'

Methods

ORM\QueryBuilder\QueryBuilderInterface::andParenthesis

public function andParenthesis(): $this
Add a parenthesis with AND
Returns $this  

ORM\QueryBuilder\QueryBuilderInterface::andParenthesis

↑ top


ORM\QueryBuilder\QueryBuilderInterface::andWhere

public function andWhere(
    string $column, 
    string|array $operator = '', 
    string $value = '', 
): $this
Add a where condition with AND.

QueryBuilderInterface andWhere($column[, $operator[, $value]]);

If $column has the same amount of question marks as $value - $value is the second parameter.

If there is no third parameter and no question mark in $column then the default operator is ‘=’ and $value is the second parameter.

These calls are equal:

$query->andWhere('name', '=' , 'John Doe');
$query->andWhere('name = ?', 'John Doe');
$query->andWhere('name', 'John Doe');
$query->andWhere('name = ?', ['John Doe']);
Returns $this  
Parameters
Parameter Type Description  
$column string Column or expression with placeholders  
$operator **string array** Operator, value or array of values
$value string Value (required when used with operator)  

ORM\QueryBuilder\QueryBuilderInterface::andWhere

↑ top


ORM\QueryBuilder\QueryBuilderInterface::close

public function close(
    , 
): \ORM\QueryBuilder\QueryBuilderInterface|\ORM\QueryBuilder\ParenthesisInterface
Close parenthesis
Returns ORM\QueryBuilder\QueryBuilderInterface|ORM\QueryBuilder\ParenthesisInterface  

ORM\QueryBuilder\QueryBuilderInterface::close

↑ top


ORM\QueryBuilder\QueryBuilderInterface::column

public function column(
    string $column, 
    array $args = [], 
    string $alias = '', 
): $this
Add $column

Optionally you can provide an expression with question marks as placeholders filled with $args.

Returns $this  
Parameters
Parameter Type Description
$column string Column or expression to fetch
$args array Arguments for expression
$alias string Alias for the column

ORM\QueryBuilder\QueryBuilderInterface::column

↑ top


ORM\QueryBuilder\QueryBuilderInterface::columns

public function columns(array|null $columns = null): $this
Set $columns
Returns $this  
Parameters
Parameter Type Description  
$columns **array null**  

ORM\QueryBuilder\QueryBuilderInterface::columns

↑ top


ORM\QueryBuilder\QueryBuilderInterface::fullJoin

public function fullJoin(
    string $tableName, 
    string|bool $expression = '', 
    string $alias = '', 
    array $args = [], 
): $this|\ORM\QueryBuilder\ParenthesisInterface
Full (outer) join $tableName with $options

When no expression got provided self get returned. If you want to get a parenthesis the parameter empty can be set to false.

ATTENTION: here the default value of empty got changed - defaults to yes

Returns $this|ORM\QueryBuilder\ParenthesisInterface  
Parameters
Parameter Type Description  
$tableName string Table to join  
$expression **string bool** Expression, single column name or boolean to create an empty join
$alias string Alias for the table  
$args array Arguments for expression  

ORM\QueryBuilder\QueryBuilderInterface::fullJoin

↑ top


ORM\QueryBuilder\QueryBuilderInterface::getExpression

public function getExpression(): string
Get the expression

Returns the complete expression inside this parenthesis.

Returns string  

ORM\QueryBuilder\QueryBuilderInterface::getExpression

↑ top


ORM\QueryBuilder\QueryBuilderInterface::getQuery

public function getQuery(): string
Get the query / select statement

Builds the statement from current where conditions, joins, columns and so on.

Returns string  

ORM\QueryBuilder\QueryBuilderInterface::getQuery

↑ top


ORM\QueryBuilder\QueryBuilderInterface::groupBy

public function groupBy(string $column, array $args = []): $this
Group By $column

Optionally you can provide an expression in $column with question marks as placeholders.

Returns $this  
Parameters
Parameter Type Description
$column string Column or expression for groups
$args array Arguments for expression

ORM\QueryBuilder\QueryBuilderInterface::groupBy

↑ top


ORM\QueryBuilder\QueryBuilderInterface::join

public function join(
    string $tableName, 
    string|bool $expression = '', 
    string $alias = '', 
    array $args = [], 
): $this|\ORM\QueryBuilder\ParenthesisInterface
(Inner) join $tableName with $options

When no expression got provided a ParenthesisInterface get returned. If this parenthesis not get filled you will most likely get an error from your database. If you don’t want to get a parenthesis the parameter empty can be set to true.

Returns $this|ORM\QueryBuilder\ParenthesisInterface  
Parameters
Parameter Type Description  
$tableName string Table to join  
$expression **string bool** Expression, single column name or boolean to create an empty join
$alias string Alias for the table  
$args array Arguments for expression  

ORM\QueryBuilder\QueryBuilderInterface::join

↑ top


ORM\QueryBuilder\QueryBuilderInterface::leftJoin

public function leftJoin(
    string $tableName, 
    string|bool $expression = '', 
    string $alias = '', 
    array $args = [], 
): $this|\ORM\QueryBuilder\ParenthesisInterface
Left (outer) join $tableName with $options

When no expression got provided a ParenthesisInterface get returned. If this parenthesis not get filled you will most likely get an error from your database. If you don’t want to get a parenthesis the parameter empty can be set to true.

Returns $this|ORM\QueryBuilder\ParenthesisInterface  
Parameters
Parameter Type Description  
$tableName string Table to join  
$expression **string bool** Expression, single column name or boolean to create an empty join
$alias string Alias for the table  
$args array Arguments for expression  

ORM\QueryBuilder\QueryBuilderInterface::leftJoin

↑ top


ORM\QueryBuilder\QueryBuilderInterface::limit

public function limit(int $limit): $this
Set $limit

Limits the amount of rows fetched from database.

Returns $this  
Parameters
Parameter Type Description
$limit int The limit to set

ORM\QueryBuilder\QueryBuilderInterface::limit

↑ top


ORM\QueryBuilder\QueryBuilderInterface::modifier

public function modifier(string $modifier): $this
Add $modifier

Add query modifiers such as SQL_CALC_FOUND_ROWS or DISTINCT.

Returns $this  
Parameters
Parameter Type Description
$modifier string  

ORM\QueryBuilder\QueryBuilderInterface::modifier

↑ top


ORM\QueryBuilder\QueryBuilderInterface::offset

public function offset(int $offset): $this
Set $offset

Changes the offset (only with limit) where fetching starts in the query.

Returns $this  
Parameters
Parameter Type Description
$offset int The offset to set

ORM\QueryBuilder\QueryBuilderInterface::offset

↑ top


ORM\QueryBuilder\QueryBuilderInterface::orderBy

public function orderBy(
    string $column, 
    string $direction = self::DIRECTION_ASCENDING, 
    array $args = [], 
): $this
Order By $column in $direction

Optionally you can provide an expression in $column with question marks as placeholders.

Returns $this  
Parameters
Parameter Type Description
$column string Column or expression for order
$direction string Direction (default: ASC)
$args array Arguments for expression

ORM\QueryBuilder\QueryBuilderInterface::orderBy

↑ top


ORM\QueryBuilder\QueryBuilderInterface::orParenthesis

public function orParenthesis(): $this
Add a parenthesis with OR
Returns $this  

ORM\QueryBuilder\QueryBuilderInterface::orParenthesis

↑ top


ORM\QueryBuilder\QueryBuilderInterface::orWhere

public function orWhere(
    string $column, 
    string|array $operator = '', 
    string $value = '', 
): $this
Add a where condition with OR.

QueryBuilderInterface orWhere($column[, $operator[, $value]]);

If $column has the same amount of question marks as $value - $value is the second parameter.

If there is no third parameter and no question mark in $column then the default operator is ‘=’ and $value is the second parameter.

These calls are equal:

$query->orWhere('name', '=' , 'John Doe');
$query->orWhere('name = ?', 'John Doe');
$query->orWhere('name', 'John Doe');
$query->orWhere('name = ?', ['John Doe']);
Returns $this  
Parameters
Parameter Type Description  
$column string Column or expression with placeholders  
$operator **string array** Operator, value or array of values
$value string Value (required when used with operator)  

ORM\QueryBuilder\QueryBuilderInterface::orWhere

↑ top


ORM\QueryBuilder\QueryBuilderInterface::orWhereIn

public function orWhereIn(string|array $column, array $values): $this
Add a where in condition with OR.

If $column is an array a composite where in statement will be created

Example: whereIn(['a', 'b'], [[42, 23], [42, 23]]) gets (a,b) IN ((42,23), (23,42)) in mysql

If $values is empty the expression will be 1 = 0 because an empty parenthesis causes an error in SQL.

Returns $this  
Parameters
Parameter Type Description  
$column **string array**  
$values array    

ORM\QueryBuilder\QueryBuilderInterface::orWhereIn

↑ top


ORM\QueryBuilder\QueryBuilderInterface::orWhereNotIn

public function orWhereNotIn(string|array $column, array $values): $this
Add a where not in condition with OR.

If $column is an array a composite where in statement will be created

Example: whereIn(['a', 'b'], [[42, 23], [42, 23]]) gets (a,b) NOT IN ((42,23), (23,42)) in mysql

If $values is empty the expression will be 1 = 1 because an empty parenthesis causes an error in SQL.

Returns $this  
Parameters
Parameter Type Description  
$column **string array**  
$values array    

ORM\QueryBuilder\QueryBuilderInterface::orWhereNotIn

↑ top


ORM\QueryBuilder\QueryBuilderInterface::parenthesis

public function parenthesis(): $this
Alias for andParenthesis
Returns $this  

See Also:

ORM\QueryBuilder\QueryBuilderInterface::parenthesis

↑ top


ORM\QueryBuilder\QueryBuilderInterface::rightJoin

public function rightJoin(
    string $tableName, 
    string|bool $expression = '', 
    string $alias = '', 
    array $args = [], 
): $this|\ORM\QueryBuilder\ParenthesisInterface
Right (outer) join $tableName with $options

When no expression got provided a ParenthesisInterface get returned. If this parenthesis not get filled you will most likely get an error from your database. If you don’t want to get a parenthesis the parameter empty can be set to true.

Returns $this|ORM\QueryBuilder\ParenthesisInterface  
Parameters
Parameter Type Description  
$tableName string Table to join  
$expression **string bool** Expression, single column name or boolean to create an empty join
$alias string Alias for the table  
$args array Arguments for expression  

ORM\QueryBuilder\QueryBuilderInterface::rightJoin

↑ top


ORM\QueryBuilder\QueryBuilderInterface::where

public function where(
    string $column, 
    mixed $operator = '', 
    mixed $value = '', 
): $this
Alias for andWhere

QueryBuilderInterface where($column[, $operator[, $value]]);

If $column has the same amount of question marks as $value - $value is the second parameter.

If there is no third parameter and no question mark in $column then the default operator is ‘=’ and $value is the second parameter.

These calls are equal:

$query->where('name', '=' , 'John Doe');
$query->where('name = ?', 'John Doe');
$query->where('name', 'John Doe');
$query->where('name = ?', ['John Doe']);
Returns $this  
Parameters
Parameter Type Description
$column string Column or expression with placeholders
$operator mixed Operator, value or array of values
$value mixed Value (required when used with operator)

See Also:

ORM\QueryBuilder\QueryBuilderInterface::where

↑ top


ORM\QueryBuilder\QueryBuilderInterface::whereIn

public function whereIn(string|array $column, array $values): $this
Add a where in condition with AND.

If $column is an array a composite where in statement will be created

Example: whereIn(['a', 'b'], [[42, 23], [42, 23]]) gets (a,b) IN ((42,23), (23,42)) in mysql

If $values is empty the expression will be 1 = 0 because an empty parenthesis causes an error in SQL.

Returns $this  
Parameters
Parameter Type Description  
$column **string array**  
$values array    

ORM\QueryBuilder\QueryBuilderInterface::whereIn

↑ top


ORM\QueryBuilder\QueryBuilderInterface::whereNotIn

public function whereNotIn(string|array $column, array $values): $this
Add a where not in condition with AND.

If $column is an array a composite where in statement will be created

Example: whereIn(['a', 'b'], [[42, 23], [42, 23]]) gets (a,b) NOT IN ((42,23), (23,42)) in mysql

If $values is empty the expression will be 1 = 1 because an empty parenthesis causes an error in SQL.

Returns $this  
Parameters
Parameter Type Description  
$column **string array**  
$values array    

ORM\QueryBuilder\QueryBuilderInterface::whereNotIn

↑ top