Convienience class for creating sql queries - also the class that instantiates the specific db driver

package Query
subpackage Query_Builder

 Methods

Calls a function further down the inheritence chain

__call(string $name, array $params) : mixed

Parameters

$name

string

$params

array

Exceptions

\Query\BadMethodCallException

Returns

mixed

Constructor

__construct(\Query\Driver\Driver_Interface $db) 

Destructor

__destruct() 
codeCoverageIgnore

Retreive the number of rows in the selected table

count_all(string $table) : int

Parameters

$table

string

Returns

int

Retrieve the number of results for the generated query - used in place of the get() method

count_all_results(string $table = '') : int

Parameters

$table

string

Returns

int

Deletes data from a table

delete(string $table, mixed $where = '') : \Query\PDOStatement

Parameters

$table

string

$where

mixed

Returns

Adds the 'distinct' keyword to a query

distinct() : \Query\Query_Builder

Tell the database to give you the query plan instead of result set

explain() : \Query\Query_Builder

Specify the database table to select from

from(string $tblname) : \Query\Query_Builder

Parameters

$tblname

string

Returns

Select and retrieve all records from the current table, and/or execute current compiled query

get(mixed $table = '', int $limit = FALSE, int $offset = FALSE) : \Query\PDOStatement

Parameters

$table

$limit

int

$offset

int

Returns

Returns the generated 'delete' sql query

get_compiled_delete(string $table = "", bool $reset = TRUE) : string

Parameters

$table

string

$reset

bool

Returns

string

Returns the generated 'insert' sql query

get_compiled_insert(string $table, bool $reset = TRUE) : string

Parameters

$table

string

$reset

bool

Returns

string

Returns the generated 'select' sql query

get_compiled_select(string $table = '', bool $reset = TRUE) : string

Parameters

$table

string

$reset

bool

Returns

string

Returns the generated 'update' sql query

get_compiled_update(string $table = '', bool $reset = TRUE) : string

Parameters

$table

string

$reset

bool

Returns

string

Convience method for get() with a where clause

get_where(string $table, array $where = array(), int $limit = FALSE, int $offset = FALSE) : \Query\PDOStatement

Parameters

$table

string

$where

array

$limit

int

$offset

int

Returns

Group the results by the selected field(s)

group_by(mixed $field) : \Query\Query_Builder

Parameters

$field

mixed

Returns

Ends a query group

group_end() : \Query\Query_Builder

Adds a paren to the current query for query grouping

group_start() : \Query\Query_Builder

Generates a 'Having' clause

having(mixed $key, mixed $val = array()) : \Query\Query_Builder

Parameters

$key

mixed

$val

mixed

Returns

Creates an insert clause, and executes it

insert(string $table, mixed $data = array()) : \Query\PDOStatement

Parameters

$table

string

$data

mixed

Returns

Creates and executes a batch insertion query

insert_batch(string $table, array $data = array()) : \Query\PDOStatement

Parameters

$table

string

$data

array

Returns

Creates a join phrase in a compiled query

join(string $table, string $condition, string $type = '') : \Query\Query_Builder

Parameters

$table

string

$condition

string

$type

string

Returns

Creates a Like clause in the sql statement

like(string $field, mixed $val, string $pos = 'both') : \Query\Query_Builder

Parameters

$field

string

$val

mixed

$pos

string

Returns

Set a limit on the current sql statement

limit(int $limit, int $offset = FALSE) : \Query\Query_Builder

Parameters

$limit

int

$offset

int

Returns

Generates a NOT LIKE clause

not_like(string $field, mixed $val, string $pos = 'both') : \Query\Query_Builder

Parameters

$field

string

$val

mixed

$pos

string

Returns

Adds a paren to the current query for query grouping, prefixed with 'OR'

or_group_start() : \Query\Query_Builder

Generates a 'Having' clause prefixed with 'OR'

or_having(mixed $key, mixed $val = array()) : \Query\Query_Builder

Parameters

$key

mixed

$val

mixed

Returns

Generates an OR Like clause

or_like(string $field, mixed $val, string $pos = 'both') : \Query\Query_Builder

Parameters

$field

string

$val

mixed

$pos

string

Returns

Adds a paren to the current query for query grouping, prefixed with 'OR NOT'

or_not_group_start() : \Query\Query_Builder

Generates a OR NOT LIKE clause

or_not_like(string $field, mixed $val, string $pos = 'both') : \Query\Query_Builder

Parameters

$field

string

$val

mixed

$pos

string

Returns

Where clause prefixed with "OR"

or_where(string $key, mixed $val = array()) : \Query\Query_Builder

Parameters

$key

string

$val

mixed

Returns

Where in statement prefixed with "or"

or_where_in(string $field, mixed $val = array()) : \Query\Query_Builder

Parameters

$field

string

$val

mixed

Returns

OR WHERE NOT IN (FOO) clause

or_where_not_in(string $field, mixed $val = array()) : \Query\Query_Builder

Parameters

$field

string

$val

mixed

Returns

Order the results by the selected field(s)

order_by(string $field, string $type = "") : \Query\Query_Builder

Parameters

$field

string

$type

string

Returns

Clear out the class variables, so the next query can be run

reset_query() : void

Specifies rows to select in a query

select(string $fields) : \Query\Query_Builder

Parameters

$fields

string

Returns

Selects the average value of a field from a query

select_avg(string $field, string $as = FALSE) : \Query\Query_Builder

Parameters

$field

string

$as

string

Returns

Selects the maximum value of a field from a query

select_max(string $field, string $as = FALSE) : \Query\Query_Builder

Parameters

$field

string

$as

string

Returns

Selects the minimum value of a field from a query

select_min(string $field, string $as = FALSE) : \Query\Query_Builder

Parameters

$field

string

$as

string

Returns

Selects the sum of a field from a query

select_sum(string $field, string $as = FALSE) : \Query\Query_Builder

Parameters

$field

string

$as

string

Returns

Sets values for inserts / updates / deletes

set(mixed $key, mixed $val = NULL) : \Query\Query_Builder

Parameters

$key

mixed

$val

mixed

Returns

Creates an update clause, and executes it

update(string $table, mixed $data = array()) : \Query\PDOStatement

Parameters

$table

string

$data

mixed

Returns

Specify condition(s) in the where clause of a query Note: this function works with key / value, or a passed array with key / value pairs

where(mixed $key, mixed $val = array(), mixed $escape = NULL) : \Query\Query_Builder

Parameters

$key

mixed

$val

mixed

$escape

mixed

Returns

Where clause with 'IN' statement

where_in(mixed $field, mixed $val = array()) : \Query\Query_Builder

Parameters

$field

mixed

$val

mixed

Returns

WHERE NOT IN (FOO) clause

where_not_in(string $field, mixed $val = array()) : \Query\Query_Builder

Parameters

$field

string

$val

mixed

Returns

Add an additional set of mapping pairs to a internal map

_append_map(string $conjunction = '', string $string = '', string $type = '') : void

Parameters

$conjunction

string

$string

string

$type

string

Convert the prepared statement into readable sql

_append_query(array $vals, string $sql, string $total_time) : void

Parameters

$vals

array

$sql

string

$total_time

string

String together the sql statements for sending to the db

_compile(string $type = '', string $table = '') : \Query\$string

Parameters

$type

string

$table

string

Returns

Sub-method for generating sql strings

_compile_type(string $type = '', string $table = '') : string

Parameters

$type

string

$table

string

Returns

string

Helper function for returning sql strings

_get_compile(string $type, string $table, bool $reset) 
resturn string

Parameters

$type

string

$table

string

$reset

bool

Simplify building having clauses

_having(mixed $key, mixed $val = array(), string $conj = 'AND') : \Query\Query_Builder

Parameters

$key

mixed

$val

mixed

$conj

string

Returns

Executes the compiled query

_run(string $type, string $table, string $sql = NULL, array|null $vals = NULL) : \Query\PDOStatement

Parameters

$type

string

$table

string

$sql

string

$vals

arraynull

Returns

Method to simplify select_ methods

_select(string $field, string $as = FALSE) : string

Parameters

$field

string

$as

string

Returns

string

Do all the repeditive stuff for where/having type methods

_where(mixed $key, mixed $val = array()) : array

Parameters

$key

mixed

$val

mixed

Returns

array

Simplify where_in methods

_where_in(mixed $key, mixed $val = array(), string $in = 'IN', string $conj = 'AND') : \Query\Query_Builder

Parameters

$key

mixed

$val

mixed

$in

string
  • The (not) in fragment

$conj

string
  • The where in conjunction

Returns

Simplify generating where string

_where_string(mixed $key, mixed $val = array(), string $conj = 'AND') : \Query\Query_Builder

Parameters

$key

mixed

$val

mixed

$conj

string

Returns

 Properties

 

Convenience property for connection management

$conn_name : string

Default

""
 

The current database driver

$db : \Query\Driver\Driver_Interface

Default

 

List of queries executed

$queries : array

Default

 

Alias to $this->db->sql

$sql : \Query\SQL_Interface

Default

 

Alias to $this->db->util

$util : \Query\DB_Util

Default

 

Whether to do only an explain on the query

$explain : bool

Default

 

Compiled 'from' clause

$from_string : \Query\type

Default

 

Key/val pairs for group by clause

$group_array : array

Default

array()
 

Group by clause

$group_string : string

Default

 

Map for having clause

$having_map : array

Default

 

Value for limit string

$limit : \Query\type

Default

 

Value for offset in limit string

$offset : int

Default

 

Key/val pairs for order by clause

$order_array : array

Default

array()
 

Order by clause

$order_string : string

Default

 

Query parser class instance

$parser : \Query\Query_Parser

Default

 

Query component order mapping for complex select queries

$query_map : array

Default

array()
Format: array( 'type' => 'where', 'conjunction' => ' AND ', 'string' => 'k=?' )
 

Compiled 'select' clause

$select_string : \Query\type

Default

''
 

Keys for insert/update statement

$set_array_keys : array

Default

array()
 

Compiled arguments for insert / update

$set_string : string

Default

 

Values to apply to prepared statements

$values : array

Default

array()
 

Values to apply to where clauses in prepared statements

$where_values : array

Default

array()