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

package Query
subpackage Query

 Methods

Calls a function further down the inheritence chain

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

Parameters

$name

string

$params

array

Returns

mixed

Constructor

__construct(object $params) 

Parameters

$params

object
  • the connection parametere

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) : mixed

Parameters

$table

string

$where

mixed

Returns

mixed

Adds the 'distinct' keyword to a query

distinct() : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Returns

Specify the database table to select from

from(string $dbname) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$dbname

string

Returns

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

get($table, int $limit, int $offset) : object

Parameters

$table

$limit

int

$offset

int

Returns

object

Returns the generated 'insert' sql query

get_compiled_delete(string $table, bool $reset) : string

Parameters

$table

string

$reset

bool

Returns

string

Returns the generated 'insert' sql query

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

Parameters

$table

string

$reset

bool

Returns

string

Returns the generated 'select' sql query

get_compiled_select(string $table, bool $reset) : string

Parameters

$table

string

$reset

bool

Returns

string

Returns the generated 'insert' sql query

get_compiled_update(string $table, bool $reset) : string

Parameters

$table

string

$reset

bool

Returns

string

Convience method for get() with a where clause

get_where(string $table, array $where, int $limit, int $offset) : object

Parameters

$table

string

$where

array

$limit

int

$offset

int

Returns

object

Group the results by the selected field(s)

group_by(mixed $field) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

mixed

Returns

Ends a query group

group_end() : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Returns

Adds a paren to the current query for query grouping

group_start() : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Returns

Generates a 'Having' clause

having(mixed $key, mixed $val) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

mixed

$val

mixed

Returns

Creates an insert clause, and executes it

insert(string $table, mixed $data) : mixed

Parameters

$table

string

$data

mixed

Returns

mixed

Creates a join phrase in a compiled query

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

fluent This method is part of a fluent interface and will return the same instance

Parameters

$table

string

$condition

string

$type

string

Returns

Set a limit on the current sql statement

limit(int $limit, int $offset) : string

Parameters

$limit

int

$offset

int

Returns

string

Generates a NOT LIKE clause

not_like(string $field, mixed $val, string $pos) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

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_Builder

fluent This method is part of a fluent interface and will return the same instance

Returns

Generates a 'Having' clause prefixed with 'OR'

or_having(mixed $key, mixed $val) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

mixed

$val

mixed

Returns

Generates an OR Like clause

or_like(string $field, mixed $val, string $pos) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

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_Builder

fluent This method is part of a fluent interface and will return the same instance

Returns

Generates a OR NOT LIKE clause

or_not_like(string $field, mixed $val, string $pos) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$val

mixed

$pos

string

Returns

Where clause prefixed with "OR"

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

fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

string

$val

mixed

Returns

Where in statement prefixed with "or"

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

fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$val

mixed

Returns

OR WHERE NOT IN (FOO) clause

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

fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$val

mixed

Returns

Order the results by the selected field(s)

order_by(string $field, string $type) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$type

string

Returns

Resets the query builder for the next query

reset_query() 

Specifies rows to select in a query

select(string $fields) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$fields

string

Returns

Selects the average value of a field from a query

select_avg(string $field, string $as) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$as

string

Returns

Selects the maximum value of a field from a query

select_max(string $field, string $as) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$as

string

Returns

Selects the minimum value of a field from a query

select_min(string $field, string $as) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$as

string

Returns

Selects the sum of a field from a query

select_sum(string $field, string $as) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$as

string

Returns

Sets values for inserts / updates / deletes

set(mixed $key, mixed $val) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

mixed

$val

mixed

Returns

Creates an update clause, and executes it

update(string $table, mixed $data) : mixed

Parameters

$table

string

$data

mixed

Returns

mixed

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) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

mixed

$val

mixed

Returns

Where clause with 'IN' statement

where_in(mixed $field, mixed $val) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

mixed

$val

mixed

Returns

WHERE NOT IN (FOO) clause

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

fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$val

mixed

Returns

String together the sql statements for sending to the db

_compile(string $type, string $table) : \$string

Parameters

$type

string

$table

string

Returns

\$string

Simplify building having clauses

_having(mixed $key, mixed $val, string $conj) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

mixed

$val

mixed

$conj

string

Returns

Simplify 'like' methods

_like(string $field, mixed $val, string $pos, string $like, string $conj) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$val

mixed

$pos

string

$like

string

$conj

string

Returns

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

_reset() : void

Method to simplify select_ methods

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

Parameters

$field

string

$as

string

Returns

string

Do all the repeditive stuff for where/having type methods

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

Parameters

$key

mixed

$val

mixed

Returns

array

Simplify where_in methods

_where_in(mixed $key, mixed $val, $in, $conj) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

mixed

$val

mixed

$in

string

$conj

string

Returns

Simplify generating where string

_where_string(mixed $key, mixed $val, string $conj) : \Query_Builder

fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

mixed

$val

mixed

$conj

string

Returns

 Properties

 

Convenience property for connection management

$conn_name : string

 

List of sql queries executed

$queries : array

 

Alias to $this->db->sql

$sql : \DB_PDO

 

Compiled 'from' clause

$from_string : string

 

Key/val pairs for group by clause

$group_array : array

 

Group by clause

$group_string : string

 

Map for having clause

$having_map : array

 

Value for limit string

$limit : int

 

Value for offset in limit string

$offset : int

 

Key/val pairs for order by clause

$order_array : array

 

Order by clause

$order_string : string

 

Query component order mapping for complex select queries

$query_map : array

Format:

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

 

Compiled 'select' clause

$select_string : string

 

Keys for insert/update statement

$set_array_keys : array

 

Compiled arguments for insert / update

$set_string : string

 

Values to apply to prepared statements

$values : array