PHP Class Bluz\Db\Query\Select

Inheritance: extends AbstractBuilder, use trait Bluz\Db\Query\Traits\From, use trait Bluz\Db\Query\Traits\Where, use trait Bluz\Db\Query\Traits\Order, use trait Bluz\Db\Query\Traits\Limit
显示文件 Open project: bluzphp/framework Class Usage Examples

Protected Properties

Property Type Description
$fetchType PDO fetch types or object class

Public Methods

Method Description
addGroupBy ( variadic $groupBy ) : Select Adds a grouping expression to the query.
addSelect ( string $select ) : Select Adds an item that is to be returned in the query result.
andHaving ( variadic $condition ) : Select Adds a restriction over the groups of the query, forming a logical conjunction with any existing having restrictions
execute ( integer | string | object $fetchType = null ) : integer | string | array
getSql ( ) : string
groupBy ( variadic $groupBy ) : Select Specifies a grouping over the results of the query.
having ( variadic $condition ) : Select Specifies a restriction over the groups of the query.
innerJoin ( string $fromAlias, string $join, string $alias, string $condition = null ) : Select Creates and adds a join to the query
join ( string $fromAlias, string $join, string $alias, string $condition = null ) : Select Creates and adds a join to the query
leftJoin ( string $fromAlias, string $join, string $alias, string $condition = null ) : Select Creates and adds a left join to the query.
orHaving ( variadic $condition ) : Select Adds a restriction over the groups of the query, forming a logical disjunction with any existing having restrictions
rightJoin ( string $fromAlias, string $join, string $alias, string $condition = null ) : Select Creates and adds a right join to the query.
select ( variadic $select ) : Select Specifies an item that is to be returned in the query result Replaces any previously specified selections, if any
setFetchType ( string $fetchType ) : Select Setup fetch type, any of PDO, or any Class
setPage ( integer $page = 1 ) : Select Setup offset like a page number, start from 1

Protected Methods

Method Description
getSQLForJoins ( string $fromAlias ) : string Generate SQL string for JOINs

Method Details

addGroupBy() public method

Example $sb = new Select(); $sb ->select('u.name') ->from('users', 'u') ->groupBy('u.lastLogin'); ->addGroupBy('u.createdAt')
public addGroupBy ( variadic $groupBy ) : Select
$groupBy variadic the grouping expression
return Select instance

addSelect() public method

Example $sb = new Select(); $sb ->select('u.id') ->addSelect('p.id') ->from('users', 'u') ->leftJoin('u', 'phone', 'u.id = p.user_id');
public addSelect ( string $select ) : Select
$select string the selection expression
return Select instance

andHaving() public method

Adds a restriction over the groups of the query, forming a logical conjunction with any existing having restrictions
public andHaving ( variadic $condition ) : Select
$condition variadic the query restriction predicates
return Select

execute() public method

public execute ( integer | string | object $fetchType = null ) : integer | string | array
$fetchType integer | string | object
return integer | string | array

getSQLForJoins() protected method

Generate SQL string for JOINs
protected getSQLForJoins ( string $fromAlias ) : string
$fromAlias string alias of table
return string

getSql() public method

public getSql ( ) : string
return string

groupBy() public method

Replaces any previously specified groupings, if any. Example $sb = new Select(); $sb ->select('u.name') ->from('users', 'u') ->groupBy('u.id');
public groupBy ( variadic $groupBy ) : Select
$groupBy variadic the grouping expression
return Select instance

having() public method

Replaces any previous having restrictions, if any
public having ( variadic $condition ) : Select
$condition variadic the query restriction predicates
return Select

innerJoin() public method

Example $sb = new Select(); $sb ->select('u.name') ->from('users', 'u') ->innerJoin('u', 'phone', 'p', 'p.is_primary = 1');
public innerJoin ( string $fromAlias, string $join, string $alias, string $condition = null ) : Select
$fromAlias string the alias that points to a from clause
$join string the table name to join
$alias string the alias of the join table
$condition string the condition for the join
return Select instance

join() public method

Example $sb = new Select(); $sb ->select('u.name') ->from('users', 'u') ->join('u', 'phone', 'p', 'p.is_primary = 1');
public join ( string $fromAlias, string $join, string $alias, string $condition = null ) : Select
$fromAlias string the alias that points to a from clause
$join string the table name to join
$alias string the alias of the join table
$condition string the condition for the join
return Select instance

leftJoin() public method

Example $sb = new Select(); $sb ->select('u.name') ->from('users', 'u') ->leftJoin('u', 'phone', 'p', 'p.is_primary = 1');
public leftJoin ( string $fromAlias, string $join, string $alias, string $condition = null ) : Select
$fromAlias string the alias that points to a from clause
$join string the table name to join
$alias string the alias of the join table
$condition string the condition for the join
return Select instance

orHaving() public method

Adds a restriction over the groups of the query, forming a logical disjunction with any existing having restrictions
public orHaving ( variadic $condition ) : Select
$condition variadic the query restriction predicates
return Select

rightJoin() public method

Example $sb = new Select(); $sb ->select('u.name') ->from('users', 'u') ->rightJoin('u', 'phone', 'p', 'p.is_primary = 1');
public rightJoin ( string $fromAlias, string $join, string $alias, string $condition = null ) : Select
$fromAlias string the alias that points to a from clause
$join string the table name to join
$alias string the alias of the join table
$condition string the condition for the join
return Select instance

select() public method

Example $sb = new Select(); $sb ->select('u.id', 'p.id') ->from('users', 'u') ->leftJoin('u', 'phone', 'p', 'u.id = p.user_id');
public select ( variadic $select ) : Select
$select variadic the selection expressions
return Select instance

setFetchType() public method

Setup fetch type, any of PDO, or any Class
public setFetchType ( string $fetchType ) : Select
$fetchType string
return Select instance

setPage() public method

Setup offset like a page number, start from 1
public setPage ( integer $page = 1 ) : Select
$page integer
return Select

Property Details

$fetchType protected_oe property

PDO fetch types or object class
protected $fetchType