PHP Class ManaPHP\Mvc\Model\QueryBuilder

Inheritance: extends ManaPHP\Component, implements ManaPHP\Mvc\Model\QueryBuilderInterface
Datei anzeigen Open project: manaphp/manaphp

Protected Properties

Property Type Description
$_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

Public Methods

Method Description
__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

Protected Methods

Method Description
_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

Method Details

__construct() public method

$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 method

protected _buildCacheData ( array $rows, integer $total ) : array
$rows array
$total integer
return array

_buildSql() protected method

Returns a SQL statement built based on the builder parameters
protected _buildSql ( ) : string
return string

_getCacheOptions() protected method

protected _getCacheOptions ( integer | array $cacheOptions ) : array
$cacheOptions integer | array
return array

_getTotalRows() protected method

protected _getTotalRows ( ) : integer
return integer

_getUnionSql() protected method

protected _getUnionSql ( ) : string
return string

addFrom() public method

$builder->addFrom('Robots', 'r');
public addFrom ( string | ManaPHP\Mvc\Model\QueryBuilderInterface $model, string $alias = null ) : static
$model string | ManaPHP\Mvc\Model\QueryBuilderInterface
$alias string
return static

andWhere() public method

$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
return static

betweenWhere() public method

$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
return static

columns() public method

$builder->columns(array('id', 'name'));
public columns ( string $columns ) : static
$columns string
return static

distinct() public method

Sets SELECT DISTINCT / SELECT ALL flag
public distinct ( boolean $distinct ) : static
$distinct boolean
return static

execute() public method

public execute ( integer | array $cacheOptions = null ) : array
$cacheOptions integer | array
return array

executeEx() public method

build the query and execute it.
public executeEx ( integer | string &$totalRows, integer | array $cacheOptions = null ) : array
$totalRows integer | string
$cacheOptions integer | array
return array

forUpdate() public method

$builder->forUpdate(true);
public forUpdate ( boolean $forUpdate = true ) : static
$forUpdate boolean
return static

from() public method

$builder->from('Robots'); $builder->from(array('Robots', 'RobotsParts'));
public from ( string | array $models ) : static
$models string | array
return static

getBind() public method

public getBind ( )

getModels() public method

public getModels ( ) : array
return array

getSql() public method

public getSql ( ) : string
return string

groupBy() public method

$builder->groupBy(array('Robots.name'));
public groupBy ( string $groupBy ) : static
$groupBy string
return static

having() public method

$builder->having('SUM(Robots.price) > 0');
public having ( string $having, array $bind = [] ) : static
$having string
$bind array
return static

inWhere() public method

$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
return static

innerJoin() public method

$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
return static

join() public method

$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
return static

leftJoin() public method

$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
return static

limit() public method

$builder->limit(100); $builder->limit(100, 20);
public limit ( integer $limit, integer $offset ) : static
$limit integer
$offset integer
return static

notBetweenWhere() public method

$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
return static

notInWhere() public method

$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
return static

orderBy() public method

$builder->orderBy('Robots.name'); $builder->orderBy(array('1', 'Robots.name'));
public orderBy ( string $orderBy ) : static
$orderBy string
return static

page() public method

public page ( integer $size, integer $current = 1 ) : static
$size integer
$current integer
return static

paginate() public method

public paginate ( integer $size, integer $page, integer | array $cacheOptions = null ) : static
$size integer
$page integer
$cacheOptions integer | array
return static

rightJoin() public method

$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
return static

setBind() public method

Set default bind parameters
public setBind ( array $bind, boolean $merge = true ) : static
$bind array
$merge boolean
return static

unionAll() public method

public unionAll ( ManaPHP\Mvc\Model\QueryBuilderInterface[] $builders ) : static
$builders ManaPHP\Mvc\Model\QueryBuilderInterface[]
return static

unionDistinct() public method

public unionDistinct ( ManaPHP\Mvc\Model\QueryBuilderInterface[] $builders ) : static
$builders ManaPHP\Mvc\Model\QueryBuilderInterface[]
return static

where() public method

$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
return static

Property Details

$_bind protected_oe property

protected array $_bind
return array

$_columns protected_oe property

protected string $_columns
return string

$_conditions protected_oe property

protected array $_conditions
return array

$_distinct protected_oe property

protected bool $_distinct
return boolean

$_forUpdate protected_oe property

protected bool $_forUpdate
return boolean

$_group protected_oe property

protected string $_group
return string

$_having protected_oe property

protected array $_having
return array

$_hiddenParamNumber protected_oe static_oe property

protected static int $_hiddenParamNumber
return integer

$_joins protected_oe property

protected array $_joins
return array

$_limit protected_oe property

protected int $_limit
return integer

$_models protected_oe property

protected array $_models
return array

$_offset protected_oe property

protected int $_offset
return integer

$_order protected_oe property

protected string $_order
return string

$_sql protected_oe property

protected string $_sql
return string

$_union protected_oe property

protected array $_union
return array