SCHLIX\cmsSQLQueryBuilder

Public Attributes

public SELECT= 0
public DELETE= 1
public UPDATE= 2
public INSERT= 3
public STATE_DIRTY= 0
public STATE_CLEAN= 1

Protected Methods

protected stringescapeArrayForInsert(array $key_values)
Escape array to prevent SQL injection
protected stringescapeArrayForUpdate(array $key_values, $escape_value=true)
Escape array to prevent SQL injection
protected stringescapeValue(string $s)
Escape string if it's avalue, don't escape it if it's a variable starting with ':'.

Public Methods

public __construct($connection=null)
Initializes a new QueryBuilder.
public integergetType()
Gets the type of the currently built query.
public getConnection()
Gets the associated DBAL Connection for this query builder.
public integer Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.getState()
Gets the state of this query builder instance.
public mixedexecute(array $data=NULL)
Executes this query using the bound parameters and their types.
public mixedgetQueryResultArray(array $data=NULL)
Executes this query using the bound parameters and their types.
public intgetQueryResultCount($data=NULL)
Returns the number of rows
public mixedgetQueryResultSingleRow(array $data=NULL)
Executes this query using the bound parameters and their types.
public string The SQL query string.getSQL()
Gets the complete SQL string formed by the current specifications of this QueryBuilder. $qb = $em->createQueryBuilder() ->select('u') ->from('User', 'u') echo $qb->getSQL(); // SELECT u FROM User u
public startEnd(int $start, int $end, bool $force_limit=true)
Set the start & end
public limitOffset(int $limit, int $offset, bool $force_limit=true)
Set the limit & offset
public $this instance.setMaxResults(integer $maxResults)
Sets the maximum number of results to retrieve (the "limit").
public integer The maximum number of results.getMaxResults()
Gets the maximum number of results the query object was set to retrieve (the "limit"). Returns NULL if setMaxResults was not applied to this query builder.
public $this instance.add(string $sqlPartName, string $sqlPart, boolean $append=false)
Either appends to or replaces a single, generic query part. The available parts are: 'select', 'from', 'set', 'where', 'groupBy', 'having' and 'orderBy'.
public $this instance.select(mixed $select=null)
Specifies an item that is to be returned in the query result. Replaces any previously specified selections, if any. $qb = $conn->createQueryBuilder() ->select('u.id', 'p.id') ->from('users', 'u') ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
public $this instance.delete(string $delete=null, string $alias=null)
Turns the query being built into a bulk delete query that ranges over a certain table. $qb = $conn->createQueryBuilder() ->delete('users', 'u') ->where('u.id = :user_id'); ->setParameter(':user_id', 1);
public $this instance.update(string $update=null, string $alias=null)
Turns the query being built into a bulk update query that ranges over a certain table $qb = $conn->createQueryBuilder() ->update('users', 'u') ->set('u.password', md5('password')) ->where('u.id = ?');
public $thisinsertInto(string $table=null)
insertinto('table', ['id' => 'value'], true/false) if automatic escape is specified, then it will automatically escape it
public $thisvalues(array $values, bool $automatic_escape=true)
if automatic escape is specified, then it will automatically escape it
public onDuplicateKeyUpdate($values, $automatic_escape=true)
public $this instance.from(string $from, string $alias=null)
Creates and adds a query root corresponding to the table identified by the given alias, forming a cartesian product with any existing query roots. $qb = $conn->createQueryBuilder() ->select('u.id') ->from('users', 'u')
public $this instance.innerJoin(string $fromAlias, string $join, string $alias, string $condition=null)
Creates and adds a join to the query. $qb = $conn->createQueryBuilder() ->select('u.name') ->from('users', 'u') ->innerJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
public $this instance.leftJoin(string $fromAlias, string $join, string $alias, string $condition=null)
Creates and adds a left join to the query. $qb = $conn->createQueryBuilder() ->select('u.name') ->from('users', 'u') ->leftJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
public $this instance.rightJoin(string $fromAlias, string $join, string $alias, string $condition=null)
Creates and adds a right join to the query. $qb = $conn->createQueryBuilder() ->select('u.name') ->from('users', 'u') ->rightJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
public $this instance.set(string $key_values, bool $automatic_escape=true)
Sets a new value for a column in a bulk update query. $qb = $conn->createQueryBuilder() ->update('users', 'u') ->set(['u.password', md5('password')]) ->where('u.id = ?');
public $this instance.where(mixed $predicates)
Specifies one or more restrictions to the query result. Replaces any previously specified restrictions, if any. $qb = $conn->createQueryBuilder() ->select('u.name') ->from('users', 'u') ->where('u.id = ?'); $qb->update('users', 'u') ->set('u.password', md5('password')) ->where(['x = 1', 'AND', ['id = :id','AND','x = 1', 'AND','x = z'], 'OR', 'x = 1', 'AND',['x = 1','AND','z = 5'] ]);
public $this instance.groupBy(mixed $groupBy)
Specifies a grouping over the results of the query. Replaces any previously specified groupings, if any. $qb = $conn->createQueryBuilder() ->select('u.name') ->from('users', 'u') ->groupBy('u.id');
public $this instance.setValue(string $column, string $value)
Sets a value for a column in an insert query. $qb = $conn->createQueryBuilder() ->insert('users') ->values( array( 'name' => '?' ) ) ->setValue('password', '?');
public $this instance.having(mixed $having)
Specifies a restriction over the groups of the query. Replaces any previous having restrictions, if any.
public field($fieldname)
public $thisorderBy(array $opt)
Specifies an ordering for the query results. Parameter must be in the form of key => sort direction. For example: orderBy('id' => 'DESC', 'name' => 'ASC')
public mixedgetPart(string $queryPartName)
Gets a query part by its name.
public arraygetParts()
Gets all query parts.
public $this instance.reset(array $queryPartNames=null)
Resets SQL parts.
public $this instance.resetQueryPart(string $queryPartName)
Resets a single SQL part.
public string The string representation of this QueryBuilder.__toString()
Gets a string representation of this QueryBuilder which corresponds to the final SQL query being constructed.