# \QueryQuery_Builder

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

## Summary

Methods
Properties
Constants
__construct()
__destruct()
__call()
select()
select_max()
select_min()
select_avg()
select_sum()
distinct()
explain()
from()
like()
or_like()
not_like()
or_not_like()
having()
or_having()
where()
or_where()
where_in()
or_where_in()
where_not_in()
or_where_not_in()
set()
join()
group_by()
order_by()
limit()
group_start()
or_group_start()
or_not_group_start()
group_end()
get()
get_where()
count_all()
count_all_results()
insert()
insert_batch()
update()
delete()
get_compiled_select()
get_compiled_insert()
get_compiled_update()
get_compiled_delete()
reset_query()
$conn_name
$queries
$db
$util
$sql
KEY
VALUE
BOTH
_mixed_set()
_select()
_get_compile()
_like()
_having()
_where()
_where_string()
_where_in()
_run()
_append_map()
_append_query()
_compile_type()
_compile()
$select_string
$from_string
$set_string
$order_string
$group_string
$set_array_keys
$order_array
$group_array
$values
$where_values
$limit
$offset
$query_map
$having_map
$explain
$parser
N/A
No private methods found
$string_vars
$array_vars
N/A

File
  src/Query/Query_Builder.php
Package
  Query\Query_Builder
Class hierarchy
  \Query\Abstract_Query_Builder
  \Query\Query_Builder
Implements
  \Query\Query_Builder_Interface

## Tags

None found

## Constants

### KEY

    KEY

#

Inherited from
  \Query\Abstract_Query_Builder

## Tags

None found

### VALUE

    VALUE

#

Inherited from
  \Query\Abstract_Query_Builder

## Tags

None found

### BOTH

    BOTH

#

Inherited from
  \Query\Abstract_Query_Builder

## Tags

None found

## Properties

### $conn_name

    $conn_name : string

Convenience property for connection management

#### Type

string

#

## Tags

None found

### $queries

    $queries : array

List of queries executed

#### Type

array

#

## Tags

None found

### $db

    $db : \Query\Driver_Interface

The current database driver

#### Type

\Query\Driver_Interface

#

## Tags

None found

### $util

    $util : \Query\Abstract_Util

Alias to driver util class

#### Type

\Query\Abstract_Util

#

## Tags

None found

### $sql

    $sql : \Query\SQL_Interface

Alias to driver sql class

#### Type

\Query\SQL_Interface

#

## Tags

None found

### $select_string

    $select_string : string

Compiled 'select' clause

#### Type

string

#

## Tags

None found

### $from_string

    $from_string : string

Compiled 'from' clause

#### Type

string

#

## Tags

None found

### $set_string

    $set_string : string

Compiled arguments for insert / update

#### Type

string

#

## Tags

None found

### $order_string

    $order_string : string

Order by clause

#### Type

string

#

## Tags

None found

### $group_string

    $group_string : string

Group by clause

#### Type

string

#

## Tags

None found

### $set_array_keys

    $set_array_keys : array

Keys for insert/update statement

#### Type

array

#

## Tags

None found

### $order_array

    $order_array : array

Key/val pairs for order by clause

#### Type

array

#

## Tags

None found

### $group_array

    $group_array : array

Key/val pairs for group by clause

#### Type

array

#

## Tags

None found

### $values

    $values : array

Values to apply to prepared statements

#### Type

array

#

## Tags

None found

### $where_values

    $where_values : array

Values to apply to where clauses in prepared statements

#### Type

array

#

## Tags

None found

### $limit

    $limit : integer

Value for limit string

#### Type

integer

#

## Tags

None found

### $offset

    $offset : boolean|integer

Value for offset in limit string

#### Type

boolean|integer

#

## Tags

None found

### $query_map

    $query_map : array

Query component order mapping for complex select queries

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

#### Type

array

#

## Tags

None found

### $having_map

    $having_map : array

Map for having clause

#### Type

array

#

## Tags

None found

### $explain

    $explain : boolean

Whether to do only an explain on the query

#### Type

boolean

#

## Tags

None found

### $parser

    $parser : \Query\Query_Parser

Query parser class instance

#### Type

\Query\Query_Parser

#

## Tags

None found

### $string_vars

    $string_vars : array

String class values to be reset

#### Type

array

#

## Tags

None found

### $array_vars

    $array_vars : array

Array class variables to be reset

#### Type

array

#

## Tags

None found

## Methods

### __construct()

    __construct(\Query\Driver_Interface  $db, \Query\Query_Parser  $parser)

Constructor

#### Parameters

\Query\Driver_Interface | $db |
\Query\Query_Parser | $parser |

#

## Tags

None found

### __destruct()

    __destruct()

Destructor

#

## Tags

codeCoverageIgnore |

### __call()

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

Calls a function further down the inheritence chain

#### Parameters

string | $name |
array | $params |

#### Throws

\BadMethodCallException

#### Returns

mixed

#

## Tags

None found

### select()

    select(string  $fields) : \Query\Query_Builder

Specifies rows to select in a query

#### Parameters

string | $fields |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### select_max()

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

Selects the maximum value of a field from a query

#### Parameters

string | $field |
string|FALSE | $as |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### select_min()

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

Selects the minimum value of a field from a query

#### Parameters

string | $field |
string|boolean | $as |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### select_avg()

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

Selects the average value of a field from a query

#### Parameters

string | $field |
string|boolean | $as |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### select_sum()

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

Selects the sum of a field from a query

#### Parameters

string | $field |
string|boolean | $as |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### distinct()

    distinct() : \Query\Query_Builder

Adds the 'distinct' keyword to a query

#### Returns

\Query\Query_Builder

#

## Tags

None found

### explain()

    explain() : \Query\Query_Builder

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

#### Returns

\Query\Query_Builder

#

## Tags

None found

### from()

    from(string  $tblname) : \Query\Query_Builder

Specify the database table to select from

#### Parameters

string | $tblname |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### like()

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

Creates a Like clause in the sql statement

#### Parameters

string | $field |
mixed | $val |
string | $pos |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### or_like()

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

Generates an OR Like clause

#### Parameters

string | $field |
mixed | $val |
string | $pos |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### not_like()

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

Generates a NOT LIKE clause

#### Parameters

string | $field |
mixed | $val |
string | $pos |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### or_not_like()

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

Generates a OR NOT LIKE clause

#### Parameters

string | $field |
mixed | $val |
string | $pos |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### having()

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

Generates a 'Having' clause

#### Parameters

mixed | $key |
mixed | $val |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### or_having()

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

Generates a 'Having' clause prefixed with 'OR'

#### Parameters

mixed | $key |
mixed | $val |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### where()

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

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

#### Parameters

mixed | $key |
mixed | $val |
mixed | $escape |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### or_where()

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

Where clause prefixed with "OR"

#### Parameters

string | $key |
mixed | $val |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### where_in()

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

Where clause with 'IN' statement

#### Parameters

mixed | $field |
mixed | $val |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### or_where_in()

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

Where in statement prefixed with "or"

#### Parameters

string | $field |
mixed | $val |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### where_not_in()

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

WHERE NOT IN (FOO) clause

#### Parameters

string | $field |
mixed | $val |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### or_where_not_in()

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

OR WHERE NOT IN (FOO) clause

#### Parameters

string | $field |
mixed | $val |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### set()

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

Sets values for inserts / updates / deletes

#### Parameters

mixed | $key |
mixed | $val |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### join()

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

Creates a join phrase in a compiled query

#### Parameters

string | $table |
string | $condition |
string | $type |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### group_by()

    group_by(mixed  $field) : \Query\Query_Builder

Group the results by the selected field(s)

#### Parameters

mixed | $field |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### order_by()

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

Order the results by the selected field(s)

#### Parameters

string | $field |
string | $type |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### limit()

    limit(integer  $limit, integer|boolean  $offset = FALSE) : \Query\Query_Builder

Set a limit on the current sql statement

#### Parameters

integer | $limit |
integer|boolean | $offset |

#### Returns

\Query\Query_Builder

#

## Tags

None found

### group_start()

    group_start() : \Query\Query_Builder

Adds a paren to the current query for query grouping

#### Returns

\Query\Query_Builder

#

## Tags

None found

### or_group_start()

    or_group_start() : \Query\Query_Builder

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

#### Returns

\Query\Query_Builder

#

## Tags

None found

### or_not_group_start()

    or_not_group_start() : \Query\Query_Builder

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

#### Returns

\Query\Query_Builder

#

## Tags

None found

### group_end()

    group_end() : \Query\Query_Builder

Ends a query group

#### Returns

\Query\Query_Builder

#

## Tags

None found

### get()

    get(  $table = '', integer|boolean  $limit = FALSE, integer|boolean  $offset = FALSE) : \PDOStatement

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

#### Parameters

| $table |
integer|boolean | $limit |
integer|boolean | $offset |

#### Returns

\PDOStatement

#

## Tags

None found

### get_where()

    get_where(string  $table, array  $where = array(), integer|boolean  $limit = FALSE, integer|boolean  $offset = FALSE) : \PDOStatement

Convenience method for get() with a where clause

#### Parameters

string | $table |
array | $where |
integer|boolean | $limit |
integer|boolean | $offset |

#### Returns

\PDOStatement

#

## Tags

None found

### count_all()

    count_all(string  $table) : integer

Retreive the number of rows in the selected table

#### Parameters

string | $table |

#### Returns

integer

#

## Tags

None found

### count_all_results()

    count_all_results(string  $table = '') : integer

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

#### Parameters

string | $table |

#### Returns

integer

#

## Tags

None found

### insert()

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

Creates an insert clause, and executes it

#### Parameters

string | $table |
mixed | $data |

#### Returns

\PDOStatement

#

## Tags

None found

### insert_batch()

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

Creates and executes a batch insertion query

#### Parameters

string | $table |
array | $data |

#### Returns

\PDOStatement

#

## Tags

None found

### update()

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

Creates an update clause, and executes it

#### Parameters

string | $table |
mixed | $data |

#### Returns

\PDOStatement

#

## Tags

None found

### delete()

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

Deletes data from a table

#### Parameters

string | $table |
mixed | $where |

#### Returns

\PDOStatement

#

## Tags

None found

### get_compiled_select()

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

Returns the generated 'select' sql query

#### Parameters

string | $table |
boolean | $reset |

#### Returns

string

#

## Tags

None found

### get_compiled_insert()

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

Returns the generated 'insert' sql query

#### Parameters

string | $table |
boolean | $reset |

#### Returns

string

#

## Tags

None found

### get_compiled_update()

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

Returns the generated 'update' sql query

#### Parameters

string | $table |
boolean | $reset |

#### Returns

string

#

## Tags

None found

### get_compiled_delete()

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

Returns the generated 'delete' sql query

#### Parameters

string | $table |
boolean | $reset |

#### Returns

string

#

## Tags

None found

### reset_query()

    reset_query() : void

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

#

## Tags

None found

### _mixed_set()

    _mixed_set(array  $var, mixed  $key, mixed  $val = NULL, integer  $val_type = self::BOTH) : array

Set values in the class, with either an array or key value pair

#### Parameters

array | $var |
mixed | $key |
mixed | $val |
integer | $val_type |

#### Returns

array

#

Inherited from
  \Query\Abstract_Query_Builder

## Tags

None found

### _select()

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

Method to simplify select_ methods

#### Parameters

string | $field |
string|boolean | $as |

#### Returns

string

#

Inherited from
  \Query\Abstract_Query_Builder

## Tags

None found

### _get_compile()

    _get_compile(string  $type, string  $table, boolean  $reset) : string

Helper function for returning sql strings

#### Parameters

string | $type |
string | $table |
boolean | $reset |

#### Returns

string

#

Inherited from
  \Query\Abstract_Query_Builder

## Tags

None found

### _like()

    _like(string  $field, mixed  $val, string  $pos, string  $like = 'LIKE', string  $conj = 'AND') : \Query\Query_Builder

Simplify 'like' methods

#### Parameters

string | $field |
mixed | $val |
string | $pos |
string | $like |
string | $conj |

#### Returns

\Query\Query_Builder

#

Inherited from
  \Query\Abstract_Query_Builder

## Tags

None found

### _having()

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

Simplify building having clauses

#### Parameters

mixed | $key |
mixed | $val |
string | $conj |

#### Returns

\Query\Query_Builder

#

Inherited from
  \Query\Abstract_Query_Builder

## Tags

None found

### _where()

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

Do all the repeditive stuff for where/having type methods

#### Parameters

mixed | $key |
mixed | $val |

#### Returns

array

#

Inherited from
  \Query\Abstract_Query_Builder

## Tags

None found

### _where_string()

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

Simplify generating where string

#### Parameters

mixed | $key |
mixed | $val |
string | $defaultConj |

#### Returns

\Query\Query_Builder

#

Inherited from
  \Query\Abstract_Query_Builder

## Tags

None found

### _where_in()

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

Simplify where_in methods

#### Parameters

mixed | $key |
mixed | $val |

string

$in

- The (not) in fragment

string

$conj

- The where in conjunction

#### Returns

\Query\Query_Builder

#

Inherited from
  \Query\Abstract_Query_Builder

## Tags

None found

### _run()

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

Executes the compiled query

#### Parameters

string | $type |
string | $table |
string | $sql |
array|null | $vals |

#### Returns

\PDOStatement

#

Inherited from
  \Query\Abstract_Query_Builder

## Tags

None found

### _append_map()

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

Add an additional set of mapping pairs to a internal map

#### Parameters

string | $conjunction |
string | $string |
string | $type |

#

Inherited from
  \Query\Abstract_Query_Builder

## Tags

None found

### _append_query()

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

Convert the prepared statement into readable sql

#### Parameters

array | $vals |
string | $sql |
string | $total_time |

#

Inherited from
  \Query\Abstract_Query_Builder

## Tags

None found

### _compile_type()

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

Sub-method for generating sql strings

#### Parameters

string | $type |
string | $table |

#### Returns

string

#

Inherited from
  \Query\Abstract_Query_Builder

## Tags

None found

### _compile()

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

String together the sql statements for sending to the db

#### Parameters

string | $type |
string | $table |

#### Returns

string

#

Inherited from
  \Query\Abstract_Query_Builder

## Tags

None found

### Query_Builder.php