PHP Class Bluz\Db\Query\AbstractBuilder

Show file Open project: bluzphp/framework

Protected Properties

Property Type Description
$aliases list of table aliases
$params the query parameters
$sql the complete SQL string for this query
$sqlParts the array of SQL parts collected
$types the parameter type map of this query

Public Methods

Method Description
__toString ( ) : string Gets a string representation of this QueryBuilder which corresponds to the final SQL query being constructed.
execute ( ) : integer | string | array Execute this query using the bound parameters and their types
getParameter ( mixed $key ) : mixed Gets a (previously set) query parameter of the query being constructed
getParameters ( ) : array Gets all defined query parameters for the query being constructed
getQuery ( ) : string Return the complete SQL string formed for use
getQueryPart ( string $queryPartName ) : mixed Get a query part by its name
getSql ( ) : string Return the complete SQL string formed by the current specifications
setParameter ( string | integer $key, mixed $value, integer $type = PDO::PARAM_STR ) Sets a query parameter for the query being constructed
setParameters ( array $params, array $types = [] ) Sets a collection of query parameters for the query being constructed

Protected Methods

Method Description
addQueryPart ( string $sqlPartName, string | array $sqlPart, boolean $append = false ) Either appends to or replaces a single, generic query part
prepareCondition ( array $args = [] ) : string Prepare condition
resetQueryPart ( string $queryPartName ) Reset single SQL part
setFromQueryPart ( string $table ) setFromQueryPart

Method Details

__toString() public method

Gets a string representation of this QueryBuilder which corresponds to the final SQL query being constructed.
public __toString ( ) : string
return string The string representation of this QueryBuilder.

addQueryPart() protected method

The available parts are: 'select', 'from', 'set', 'where', 'groupBy', 'having' and 'orderBy'
protected addQueryPart ( string $sqlPartName, string | array $sqlPart, boolean $append = false )
$sqlPartName string
$sqlPart string | array
$append boolean

execute() public method

Execute this query using the bound parameters and their types
public execute ( ) : integer | string | array
return integer | string | array

getParameter() public method

Gets a (previously set) query parameter of the query being constructed
public getParameter ( mixed $key ) : mixed
$key mixed The key (index or name) of the bound parameter
return mixed The value of the bound parameter.

getParameters() public method

Gets all defined query parameters for the query being constructed
public getParameters ( ) : array
return array The currently defined query parameters

getQuery() public method

Example $sb = new SelectBuilder(); $sb ->select('u') ->from('User', 'u') ->where('id = ?', 42); echo $qb->getQuery(); // SELECT u FROM User u WHERE id = "42"
public getQuery ( ) : string
return string

getQueryPart() public method

Get a query part by its name
public getQueryPart ( string $queryPartName ) : mixed
$queryPartName string
return mixed

getSql() abstract public method

Example $sb = new SelectBuilder(); $sb ->select('u') ->from('User', 'u'); echo $qb->getSql(); // SELECT u FROM User u
abstract public getSql ( ) : string
return string The SQL query string

prepareCondition() protected method

$builder->prepareCondition("WHERE id IN (?)", [..,..]);
protected prepareCondition ( array $args = [] ) : string
$args array
return string

resetQueryPart() protected method

Reset single SQL part
protected resetQueryPart ( string $queryPartName )
$queryPartName string

setFromQueryPart() protected method

setFromQueryPart
protected setFromQueryPart ( string $table )
$table string

setParameter() public method

Example $sb = new SelectBuilder(); $sb ->select('u') ->from('users', 'u') ->where('u.id = :user_id') ->setParameter(':user_id', 1);
public setParameter ( string | integer $key, mixed $value, integer $type = PDO::PARAM_STR )
$key string | integer The parameter position or name
$value mixed The parameter value
$type integer PDO::PARAM_*

setParameters() public method

Example $sb = new SelectBuilder(); $sb ->select('u') ->from('users', 'u') ->where('u.id = :user_id1 OR u.id = :user_id2') ->setParameters([ ':user_id1' => 1, ':user_id2' => 2 ]);
public setParameters ( array $params, array $types = [] )
$params array The query parameters to set
$types array The query parameters types to set

Property Details

$aliases protected property

list of table aliases
protected $aliases

$params protected property

the query parameters
protected $params

$sql protected property

the complete SQL string for this query
protected $sql

$sqlParts protected property

the array of SQL parts collected
protected $sqlParts

$types protected property

the parameter type map of this query
protected $types