Helper for creating a mysql query (SELECT, INSERT, UPDATE, DELETE, TRUNCATE).

package webkdb
author thg2oo6
copyright Copyright (c) 2012
version 1.0
access public

 Methods

Constructs the QueryBuilder element.

__construct(string $type, string $table, mixed $fields) 

Parameters

$type

string

The type of the SQL Query string.

$table

string

The table where we perform the query.

$fields

mixed

The fields requested.

A static initialisation for the QueryBuilder class.

driver_exec(\WebKDBDriver $db_con, string $type, string $table, mixed $fields) : \QueryBuilder

To be used only with the driver class.

Parameters

$db_con

\WebKDBDriver

The connection with the database.

$type

string

The type of the SQL Query string.

$table

string

The table where we perform the query.

$fields

mixed

The fields requested.

Returns

Executes the query.

execute() : mixed

Returns

mixed

Adds values for the LIMIT clause.

limit(integer $size, integer $from) : void

Parameters

$size

integer

The size of the query.

$from

integer

From where the query will start.

Sets where to start the Query.

limit_from(integer $from) : void

Parameters

$from

integer

The position from where the query will start.

Sets the LIMIT clause size.

limit_size(integer $size) : void

Parameters

$size

integer

The size of the LIMIT.

Adds an ORDER clause to the SQL Query string.

order(string $key, string $how) : void

Parameters

$key

string

The key after what we order.

$how

string

The method of orderding (ASC/DESC).

Adds a value to the SET clause used in UPDATE and INSERT queries.

set(string $key, string $value, string $type) : void

Parameters

$key

string

The key to recive a value.

$value

string

The value to be set for a key.

$type

string

The type of the value (MYSQL, INTEGER, BLOB, STRING).

Adds a WHERE clause to the SQL Query string.

where(string $key, string $value, string $operator, string $linking) : void

Parameters

$key

string

The key needed in the query string.

$value

string

The value for the key.

$operator

string

The operator between the key and the value.

$linking

string

The link between the elements of the WHERE clause.

Parses a list with fields and returns an array with the fields parsed for a MySQL query.

_fieldParser(mixed $fields, boolean $hasKeys) : array

Parameters

$fields

mixed

The list of fields. It may be separated by: ',', ' ', '|'. Also it can be an array.

$hasKeys

boolean

If the fields are sent as an associative array, this field must be set to true.

Returns

array

Parses the from part of the LIMIT clause.

_limitFromParse() : string

Returns

string

Creates the LIMIT clause.

_limitParse() : string

Returns

string

Creates the ORDER clause.

_orderParse() : string

Returns

string

Method used for creating a string from an array.

_qbGlue(array $array, string $glue) : array

Parameters

$array

array

The array to be parsed.

$glue

string

The glue used to transform the array into a string.

Returns

array

Returns a base string for different SQL queries supported by the driver.

_qbtext() : string

(SELECT, INSERT, UPDATE,

Returns

string

Creates the WHERE clause.

_whereParse() : string

Returns

string

 Properties

 

The connection with the database driver.

$_dbcon : \WebKDBDriver

 

Used to see if the query will be executed or not.

$_execute : boolean

 

The fields of the Query string.

$_fields : array

 

From where the limit will start.

$_limit_from : integer

 

The limit size of the Query string.

$_limit_size : integer

 

The elements of the ORDER clause.

$_order : array

 

If the Query is an INSERT or UPDATE it contains keys+values.

$_set : array

 

The table for the Query string.

$_table : string

 

The type of the Query string.

$_type : string

 

The elements of the WHERE clause.

$_where : array

 Constants

 

Used for ORDER clause.

ASC 

Defines an ASCENDING order.

 

Used for ORDER clause.

DESC 

Defines an DESCENDING order.