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 |
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 |
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 |
$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 |
$builder->addFrom('Robots', 'r');
$builder->andWhere('name = "Peter"');
$builder->andWhere('name = :name: AND id > :id:', array('name' => 'Peter', 'id' => 100));
$builder->betweenWhere('price', 100.25, 200.50);
$builder->columns(array('id', 'name'));
$builder->forUpdate(true);
$builder->from('Robots');
$builder->from(array('Robots', 'RobotsParts'));
$builder->groupBy(array('Robots.name'));
$builder->having('SUM(Robots.price) > 0');
$builder->inWhere('id', [1, 2, 3]);
$builder->innerJoin('Robots');
$builder->innerJoin('Robots', 'r.id = RobotsParts.robots_id');
$builder->innerJoin('Robots', 'r.id = RobotsParts.robots_id', 'r');
$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');
$builder->leftJoin('Robots', 'r.id = RobotsParts.robots_id', 'r');
$builder->limit(100);
$builder->limit(100, 20);
$builder->notBetweenWhere('price', 100.25, 200.50);
$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 |
$builder->orderBy('Robots.name');
$builder->orderBy(array('1', 'Robots.name'));
$builder->rightJoin('Robots', 'r.id = RobotsParts.robots_id', 'r');
public unionAll ( ManaPHP\Mvc\Model\QueryBuilderInterface[] $builders ) : static | ||
$builders | ManaPHP\Mvc\Model\QueryBuilderInterface[] | |
return | static |
public unionDistinct ( ManaPHP\Mvc\Model\QueryBuilderInterface[] $builders ) : static | ||
$builders | ManaPHP\Mvc\Model\QueryBuilderInterface[] | |
return | static |
$builder->where('name = "Peter"');
$builder->where('name = :name: AND id > :id:', array('name' => 'Peter', 'id' => 100));