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

Exceptions

\BadMethodCallException

Returns

mixed

Constructor

__construct(\DB_PDO $db, object $params) 

Parameters

$db

\DB_PDO

$params

object
  • the connection parameters

Destructor

__destruct() 

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

\Query_Builder

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

explain() : \Query_Builder
fluent This method is part of a fluent interface and will return the same instance

Returns

\Query_Builder

Specify the database table to select from

from(string $tblname) : \Query_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$tblname

string

Returns

\Query_Builder

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

get(mixed $table = '', int $limit = FALSE, int $offset = FALSE) : object

Parameters

$table

$limit

int

$offset

int

Returns

object

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

\Query_Builder

Ends a query group

group_end() : \Query_Builder
fluent This method is part of a fluent interface and will return the same instance

Returns

\Query_Builder

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

\Query_Builder

Generates a 'Having' clause

having(mixed $key, mixed $val = array()) : \Query_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

mixed

$val

mixed

Returns

\Query_Builder

Creates an insert clause, and executes it

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

Parameters

$table

string

$data

mixed

Returns

mixed

Create sql for batch insert

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

Parameters

$table

string

$data

array

Returns

string

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

\Query_Builder

Creates a Like clause in the sql statement

like(string $field, mixed $val, string $pos = 'both') : \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

\Query_Builder

Set a limit on the current sql statement

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

Parameters

$limit

int

$offset

int

Returns

string

Generates a NOT LIKE clause

not_like(string $field, mixed $val, string $pos = 'both') : \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

\Query_Builder

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

\Query_Builder

Generates a 'Having' clause prefixed with 'OR'

or_having(mixed $key, mixed $val = array()) : \Query_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

mixed

$val

mixed

Returns

\Query_Builder

Generates an OR Like clause

or_like(string $field, mixed $val, string $pos = 'both') : \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

\Query_Builder

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

\Query_Builder

Generates a OR NOT LIKE clause

or_not_like(string $field, mixed $val, string $pos = 'both') : \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

\Query_Builder

Where clause prefixed with "OR"

or_where(string $key, mixed $val = array()) : \Query_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

string

$val

mixed

Returns

\Query_Builder

Where in statement prefixed with "or"

or_where_in(string $field, mixed $val = array()) : \Query_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$val

mixed

Returns

\Query_Builder

OR WHERE NOT IN (FOO) clause

or_where_not_in(string $field, mixed $val = array()) : \Query_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$val

mixed

Returns

\Query_Builder

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

\Query_Builder

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_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$fields

string

Returns

\Query_Builder

Selects the average value of a field from a query

select_avg(string $field, string $as = FALSE) : \Query_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$as

string

Returns

\Query_Builder

Selects the maximum value of a field from a query

select_max(string $field, string $as = FALSE) : \Query_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$as

string

Returns

\Query_Builder

Selects the minimum value of a field from a query

select_min(string $field, string $as = FALSE) : \Query_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$as

string

Returns

\Query_Builder

Selects the sum of a field from a query

select_sum(string $field, string $as = FALSE) : \Query_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$as

string

Returns

\Query_Builder

Sets values for inserts / updates / deletes

set(mixed $key, mixed $val = NULL) : \Query_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

mixed

$val

mixed

Returns

\Query_Builder

Creates an update clause, and executes it

update(string $table, mixed $data = array()) : 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 = array(), mixed $escape = NULL) : \Query_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

mixed

$val

mixed

$escape

mixed

Returns

\Query_Builder

Where clause with 'IN' statement

where_in(mixed $field, mixed $val = array()) : \Query_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

mixed

$val

mixed

Returns

\Query_Builder

WHERE NOT IN (FOO) clause

where_not_in(string $field, mixed $val = array()) : \Query_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$field

string

$val

mixed

Returns

\Query_Builder

String together the sql statements for sending to the db

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

Parameters

$type

string

$table

string

Returns

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_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

mixed

$val

mixed

$conj

string

Returns

\Query_Builder

Executes the compiled query

_run(string $type, string $table, bool $simple = FALSE, string $sql = NULL, mixed $vals = NULL) : mixed

Parameters

$type

string

$table

string

$simple

bool

$sql

string

$vals

mixed

Returns

mixed

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_Builder
fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

mixed

$val

mixed

$in

string
  • The (not) in fragment

$conj

string
  • The where in conjunction

Returns

\Query_Builder

Simplify generating where string

_where_string(mixed $key, mixed $val = array(), string $conj = 'AND') : \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

\Query_Builder

 Properties

 

$conn_name

$conn_name 

Default

""
 

$db

$db 

Default

 

$queries

$queries 

Default

 

$sql

$sql 

Default

 

$util

$util 

Default

 

$explain

$explain 

Default

FALSE
 

$from_string

$from_string 

Default

 

$group_array

$group_array 

Default

 

$group_string

$group_string 

Default

 

$having_map

$having_map 

Default

 

$limit

$limit 

Default

 

$offset

$offset 

Default

 

$order_array

$order_array 

Default

 

$order_string

$order_string 

Default

 

$parser

$parser 

Default

 

$query_map

$query_map 

Default

array()
 

$select_string

$select_string 

Default

 

$set_array_keys

$set_array_keys 

Default

 

$set_string

$set_string 

Default

 

$values

$values 

Default

array()
 

$where_values

$where_values 

Default

array()