PHP Class Habari\Query

See also: Posts::get
Show file Open project: habari/system

Public Properties

Property Type Description
$primary_table

Protected Properties

Property Type Description
$fields
$groupby
$having
$join_params
$joins
$limit
$offset
$orderby

Public Methods

Method Description
__construct ( $primary_table = null ) Construct a Query
column ( ) : array Execute and return the first first field from each row of this query
create ( string $primary_table = null ) : Query Static helper method to create a new query instance
distinct ( boolean $set = true ) : Query Set whether only distinct results should be returned
from ( string $primary_table ) : Query Sets the primary table for the FROM statement
get ( ) : string Obtain the SQL used to execute this query
groupby ( string $value ) : Query Set the GROUP BY clause
having ( $value )
join ( string $join, array $parameters = [], string $alias = null ) : Query Adds a JOIN table
joined ( string $alias ) : boolean Discover if a table alias is already JOINed to this query
keyvalue ( ) : array Execute and return key-value pairs from this query
limit ( integer $value ) : Query Sets the LIMIT
new_param_name ( string $prefix = 'param' ) : string Obtain a parameter name with an optionally specified prefix that has not yet been used
offset ( integer $value ) : Query Sets the OFFSET
orderby ( string $value ) : Query Set the ORDER BY clause
params ( ) : array Obtain the parameter values needed for the query
results ( string $class = null ) : array Execute and return the returns of this query
row ( string $class = null ) : object Execute and return the first row of this query
select ( array | string $fields ) : Query Adds fields to the SELECT statement
set_select ( array | string $fields ) : Query Sets fields for the SELECT statement
value ( ) : object Execute and return the first row of this query
where ( string $operator = 'AND' ) : QueryWhere Create and/or return a QueryWhere object representing the where clause of this query

Method Details

__construct() public method

Construct a Query
public __construct ( $primary_table = null )
$primary_table Name of the primary table (use {table} syntax to expand)

column() public method

Execute and return the first first field from each row of this query
public column ( ) : array
return array The result array of values

create() public static method

Static helper method to create a new query instance
public static create ( string $primary_table = null ) : Query
$primary_table string Name of the primary table (use {table} syntax to expand)
return Query A new instance of the Query class

distinct() public method

Set whether only distinct results should be returned
public distinct ( boolean $set = true ) : Query
$set boolean True if the result set should be distinct
return Query Returns $this for fluid interface

from() public method

Sets the primary table for the FROM statement
public from ( string $primary_table ) : Query
$primary_table string The primary table from which to select
return Query Returns $this for fluid interface

get() public method

Obtain the SQL used to execute this query
public get ( ) : string
return string The SQL to execute

groupby() public method

Set the GROUP BY clause
public groupby ( string $value ) : Query
$value string The GROUP BY clause
return Query Returns $this for fluid interface

having() public method

public having ( $value )

join() public method

Adds a JOIN table
public join ( string $join, array $parameters = [], string $alias = null ) : Query
$join string The table to create a join with
$parameters array An array of parameters on which the JOIN is built
$alias string An optional alias for the joined table
return Query Returns $this for fluid interface

joined() public method

Discover if a table alias is already JOINed to this query
public joined ( string $alias ) : boolean
$alias string The name of a JOIN table alias
return boolean true if the alias was used for a join

keyvalue() public method

Execute and return key-value pairs from this query
public keyvalue ( ) : array
return array The results array of QueryRecords or the specified class

limit() public method

Sets the LIMIT
public limit ( integer $value ) : Query
$value integer The LIMIT
return Query Returns $this for fluid interface

new_param_name() public static method

Obtain a parameter name with an optionally specified prefix that has not yet been used
public static new_param_name ( string $prefix = 'param' ) : string
$prefix string An optional prefix to use for a new parameter
return string the new parameter

offset() public method

Sets the OFFSET
public offset ( integer $value ) : Query
$value integer The OFFSET
return Query Returns $this for fluid interface

orderby() public method

Set the ORDER BY clause
public orderby ( string $value ) : Query
$value string The ORDER BY clause
return Query Returns $this for fluid interface

params() public method

Obtain the parameter values needed for the query
public params ( ) : array
return array An associative array containing the parameters of the query

results() public method

Execute and return the returns of this query
public results ( string $class = null ) : array
$class string The optional class to return results as
return array The results array of QueryRecords or the specified class

row() public method

Execute and return the first row of this query
public row ( string $class = null ) : object
$class string The optional class to return results as
return object The result object, a QueryRecord or the specified class

select() public method

Adds fields to the SELECT statement
public select ( array | string $fields ) : Query
$fields array | string A field or list of fields to add to existing select'ed fields
return Query Returns $this for fluid interface

set_select() public method

Sets fields for the SELECT statement
public set_select ( array | string $fields ) : Query
$fields array | string A field or list of fields to set as the fields to select, replaces existing selected fields
return Query Returns $this for fluid interface

value() public method

Execute and return the first row of this query
public value ( ) : object
return object The result object, a QueryRecord or the specified class

where() public method

Create and/or return a QueryWhere object representing the where clause of this query
public where ( string $operator = 'AND' ) : QueryWhere
$operator string The operator (AND/OR) to use between expressions in this clause
return QueryWhere An instance of the where clause for this query

Property Details

$fields protected property

protected $fields

$groupby protected property

protected $groupby

$having protected property

protected $having

$join_params protected property

protected $join_params

$joins protected property

protected $joins

$limit protected property

protected $limit

$offset protected property

protected $offset

$orderby protected property

protected $orderby

$primary_table public property

public $primary_table