PHP Класс ManaPHP\Mvc\Model\QueryBuilder

Наследование: extends ManaPHP\Component, implements ManaPHP\Mvc\Model\QueryBuilderInterface
Показать файл Открыть проект

Защищенные свойства (Protected)

Свойство Тип Описание
$_bind array
$_columns string
$_conditions array
$_distinct boolean
$_forUpdate boolean
$_group string
$_having array
$_hiddenParamNumber integer
$_joins array
$_limit integer
$_models array
$_offset integer
$_order string
$_sql string
$_union array

Открытые методы

Метод Описание
__construct ( array | string $params = null ) \ManaPHP\Mvc\Model\Query\Builder constructor
addFrom ( string | ManaPHP\Mvc\Model\QueryBuilderInterface $model, string $alias = null ) : static Add a model to take part of the query
andWhere ( string $conditions, integer | float | string | array $bind = [] ) : static Appends a condition to the current conditions using a AND operator
betweenWhere ( string $expr, integer | float $min, integer | float $max ) : static Appends a BETWEEN condition to the current conditions
columns ( string $columns ) : static Sets the columns to be queried
distinct ( boolean $distinct ) : static Sets SELECT DISTINCT / SELECT ALL flag
execute ( integer | array $cacheOptions = null ) : array
executeEx ( integer | string &$totalRows, integer | array $cacheOptions = null ) : array build the query and execute it.
forUpdate ( boolean $forUpdate = true ) : static Sets a FOR UPDATE clause
from ( string | array $models ) : static Sets the models who makes part of the query
getBind ( )
getModels ( ) : array
getSql ( ) : string
groupBy ( string $groupBy ) : static Sets a GROUP BY clause
having ( string $having, array $bind = [] ) : static Sets a HAVING condition clause. You need to escape SQL reserved words using [ and ] delimiters
inWhere ( string $expr, array | ManaPHP\Mvc\Model\QueryBuilderInterface $values ) : static Appends an IN condition to the current conditions
innerJoin ( string | ManaPHP\Mvc\Model\QueryBuilderInterface $model, string $conditions = null, string $alias = null ) : static Adds a INNER join to the query
join ( string | ManaPHP\Mvc\Model\QueryBuilderInterface $model, string $conditions = null, string $alias = null, string $type = null ) : static Adds a join to the query
leftJoin ( string | ManaPHP\Mvc\Model\QueryBuilderInterface $model, string $conditions = null, string $alias = null ) : static Adds a LEFT join to the query
limit ( integer $limit, integer $offset ) : static Sets a LIMIT clause, optionally a offset clause
notBetweenWhere ( string $expr, integer | float $min, integer | float $max ) : static Appends a NOT BETWEEN condition to the current conditions
notInWhere ( string $expr, array | ManaPHP\Mvc\Model\QueryBuilderInterface $values ) : static Appends a NOT IN condition to the current conditions
orderBy ( string $orderBy ) : static Sets a ORDER BY condition clause
page ( integer $size, integer $current = 1 ) : static
paginate ( integer $size, integer $page, integer | array $cacheOptions = null ) : static
rightJoin ( string | ManaPHP\Mvc\Model\QueryBuilderInterface $model, string $conditions = null, string $alias = null ) : static Adds a RIGHT join to the query
setBind ( array $bind, boolean $merge = true ) : static Set default bind parameters
unionAll ( ManaPHP\Mvc\Model\QueryBuilderInterface[] $builders ) : static
unionDistinct ( ManaPHP\Mvc\Model\QueryBuilderInterface[] $builders ) : static
where ( string $conditions, integer | float | string | array $bind = [] ) : static Sets the query conditions

Защищенные методы

Метод Описание
_buildCacheData ( array $rows, integer $total ) : array
_buildSql ( ) : string Returns a SQL statement built based on the builder parameters
_getCacheOptions ( integer | array $cacheOptions ) : array
_getTotalRows ( ) : integer
_getUnionSql ( ) : string

Описание методов

__construct() публичный Метод

$params = array( 'models' => array('Users'), 'columns' => array('id', 'name', 'status'), 'conditions' => array( array( "created > :min: AND created < :max:", array("min" => '2013-01-01', 'max' => '2015-01-01'), array("min" => PDO::PARAM_STR, 'max' => PDO::PARAM_STR), ), ), or 'conditions' => "created > '2013-01-01' AND created < '2015-01-01'", 'group' => array('id', 'name'), 'having' => "name = 'lily'", 'order' => array('name', 'id'), 'limit' => 20, 'offset' => 20, or 'limit' => array(20, 20), ); $queryBuilder = new \ManaPHP\Mvc\Model\Query\Builder($params);
public __construct ( array | string $params = null )
$params array | string

_buildCacheData() защищенный Метод

protected _buildCacheData ( array $rows, integer $total ) : array
$rows array
$total integer
Результат array

_buildSql() защищенный Метод

Returns a SQL statement built based on the builder parameters
protected _buildSql ( ) : string
Результат string

_getCacheOptions() защищенный Метод

protected _getCacheOptions ( integer | array $cacheOptions ) : array
$cacheOptions integer | array
Результат array

_getTotalRows() защищенный Метод

protected _getTotalRows ( ) : integer
Результат integer

_getUnionSql() защищенный Метод

protected _getUnionSql ( ) : string
Результат string

addFrom() публичный Метод

$builder->addFrom('Robots', 'r');
public addFrom ( string | ManaPHP\Mvc\Model\QueryBuilderInterface $model, string $alias = null ) : static
$model string | ManaPHP\Mvc\Model\QueryBuilderInterface
$alias string
Результат static

andWhere() публичный Метод

$builder->andWhere('name = "Peter"'); $builder->andWhere('name = :name: AND id > :id:', array('name' => 'Peter', 'id' => 100));
public andWhere ( string $conditions, integer | float | string | array $bind = [] ) : static
$conditions string
$bind integer | float | string | array
Результат static

betweenWhere() публичный Метод

$builder->betweenWhere('price', 100.25, 200.50);
public betweenWhere ( string $expr, integer | float $min, integer | float $max ) : static
$expr string
$min integer | float
$max integer | float
Результат static

columns() публичный Метод

$builder->columns(array('id', 'name'));
public columns ( string $columns ) : static
$columns string
Результат static

distinct() публичный Метод

Sets SELECT DISTINCT / SELECT ALL flag
public distinct ( boolean $distinct ) : static
$distinct boolean
Результат static

execute() публичный Метод

public execute ( integer | array $cacheOptions = null ) : array
$cacheOptions integer | array
Результат array

executeEx() публичный Метод

build the query and execute it.
public executeEx ( integer | string &$totalRows, integer | array $cacheOptions = null ) : array
$totalRows integer | string
$cacheOptions integer | array
Результат array

forUpdate() публичный Метод

$builder->forUpdate(true);
public forUpdate ( boolean $forUpdate = true ) : static
$forUpdate boolean
Результат static

from() публичный Метод

$builder->from('Robots'); $builder->from(array('Robots', 'RobotsParts'));
public from ( string | array $models ) : static
$models string | array
Результат static

getBind() публичный Метод

public getBind ( )

getModels() публичный Метод

public getModels ( ) : array
Результат array

getSql() публичный Метод

public getSql ( ) : string
Результат string

groupBy() публичный Метод

$builder->groupBy(array('Robots.name'));
public groupBy ( string $groupBy ) : static
$groupBy string
Результат static

having() публичный Метод

$builder->having('SUM(Robots.price) > 0');
public having ( string $having, array $bind = [] ) : static
$having string
$bind array
Результат static

inWhere() публичный Метод

$builder->inWhere('id', [1, 2, 3]);
public inWhere ( string $expr, array | ManaPHP\Mvc\Model\QueryBuilderInterface $values ) : static
$expr string
$values array | ManaPHP\Mvc\Model\QueryBuilderInterface
Результат static

innerJoin() публичный Метод

$builder->innerJoin('Robots'); $builder->innerJoin('Robots', 'r.id = RobotsParts.robots_id'); $builder->innerJoin('Robots', 'r.id = RobotsParts.robots_id', 'r');
public innerJoin ( string | ManaPHP\Mvc\Model\QueryBuilderInterface $model, string $conditions = null, string $alias = null ) : static
$model string | ManaPHP\Mvc\Model\QueryBuilderInterface
$conditions string
$alias string
Результат static

join() публичный Метод

$builder->join('Robots'); $builder->join('Robots', 'r.id = RobotsParts.robots_id'); $builder->join('Robots', 'r.id = RobotsParts.robots_id', 'r'); $builder->join('Robots', 'r.id = RobotsParts.robots_id', 'r', 'LEFT');
public join ( string | ManaPHP\Mvc\Model\QueryBuilderInterface $model, string $conditions = null, string $alias = null, string $type = null ) : static
$model string | ManaPHP\Mvc\Model\QueryBuilderInterface
$conditions string
$alias string
$type string
Результат static

leftJoin() публичный Метод

$builder->leftJoin('Robots', 'r.id = RobotsParts.robots_id', 'r');
public leftJoin ( string | ManaPHP\Mvc\Model\QueryBuilderInterface $model, string $conditions = null, string $alias = null ) : static
$model string | ManaPHP\Mvc\Model\QueryBuilderInterface
$conditions string
$alias string
Результат static

limit() публичный Метод

$builder->limit(100); $builder->limit(100, 20);
public limit ( integer $limit, integer $offset ) : static
$limit integer
$offset integer
Результат static

notBetweenWhere() публичный Метод

$builder->notBetweenWhere('price', 100.25, 200.50);
public notBetweenWhere ( string $expr, integer | float $min, integer | float $max ) : static
$expr string
$min integer | float
$max integer | float
Результат static

notInWhere() публичный Метод

$builder->notInWhere('id', [1, 2, 3]);
public notInWhere ( string $expr, array | ManaPHP\Mvc\Model\QueryBuilderInterface $values ) : static
$expr string
$values array | ManaPHP\Mvc\Model\QueryBuilderInterface
Результат static

orderBy() публичный Метод

$builder->orderBy('Robots.name'); $builder->orderBy(array('1', 'Robots.name'));
public orderBy ( string $orderBy ) : static
$orderBy string
Результат static

page() публичный Метод

public page ( integer $size, integer $current = 1 ) : static
$size integer
$current integer
Результат static

paginate() публичный Метод

public paginate ( integer $size, integer $page, integer | array $cacheOptions = null ) : static
$size integer
$page integer
$cacheOptions integer | array
Результат static

rightJoin() публичный Метод

$builder->rightJoin('Robots', 'r.id = RobotsParts.robots_id', 'r');
public rightJoin ( string | ManaPHP\Mvc\Model\QueryBuilderInterface $model, string $conditions = null, string $alias = null ) : static
$model string | ManaPHP\Mvc\Model\QueryBuilderInterface
$conditions string
$alias string
Результат static

setBind() публичный Метод

Set default bind parameters
public setBind ( array $bind, boolean $merge = true ) : static
$bind array
$merge boolean
Результат static

unionAll() публичный Метод

public unionAll ( ManaPHP\Mvc\Model\QueryBuilderInterface[] $builders ) : static
$builders ManaPHP\Mvc\Model\QueryBuilderInterface[]
Результат static

unionDistinct() публичный Метод

public unionDistinct ( ManaPHP\Mvc\Model\QueryBuilderInterface[] $builders ) : static
$builders ManaPHP\Mvc\Model\QueryBuilderInterface[]
Результат static

where() публичный Метод

$builder->where('name = "Peter"'); $builder->where('name = :name: AND id > :id:', array('name' => 'Peter', 'id' => 100));
public where ( string $conditions, integer | float | string | array $bind = [] ) : static
$conditions string
$bind integer | float | string | array
Результат static

Описание свойств

$_bind защищенное свойство

protected array $_bind
Результат array

$_columns защищенное свойство

protected string $_columns
Результат string

$_conditions защищенное свойство

protected array $_conditions
Результат array

$_distinct защищенное свойство

protected bool $_distinct
Результат boolean

$_forUpdate защищенное свойство

protected bool $_forUpdate
Результат boolean

$_group защищенное свойство

protected string $_group
Результат string

$_having защищенное свойство

protected array $_having
Результат array

$_hiddenParamNumber защищенное статическое свойство

protected static int $_hiddenParamNumber
Результат integer

$_joins защищенное свойство

protected array $_joins
Результат array

$_limit защищенное свойство

protected int $_limit
Результат integer

$_models защищенное свойство

protected array $_models
Результат array

$_offset защищенное свойство

protected int $_offset
Результат integer

$_order защищенное свойство

protected string $_order
Результат string

$_sql защищенное свойство

protected string $_sql
Результат string

$_union защищенное свойство

protected array $_union
Результат array