A dead simple PHP class for building SQL statements. No manual string concatenation necessary.
author | Justin Stayton |
---|---|
copyright | Copyright 2014 by Justin Stayton |
license | MIT |
package | Miner |
version | 0.10.0 |
__construct(\PDO|null $PdoConnection= null
, bool $autoQuote= true
) : \Miner
\PDO
null
optional PDO database connection
bool
optional auto-escape values, default true
\Miner
__toString() : string
string
full SQL statementandHaving(string $column, mixed $value, string $operator= self::EQUALS
, bool|null $quote= null
) : \Miner
string
colum name
mixed
value
string
optional comparison operator, default =
bool
null
optional auto-escape value, default to global
\Miner
andWhere(string $column, mixed $value, string $operator= self::EQUALS
, bool|null $quote= null
) : \Miner
string
colum name
mixed
value
string
optional comparison operator, default =
bool
null
optional auto-escape value, default to global
\Miner
autoQuote(mixed $value, bool|null $override = null
) : mixed | false
mixed
value to escape (or not)
bool
null
value-specific override for convenience
mixed
false
value (escaped or original) or false if failedcalcFoundRows() : \Miner
\Miner
closeHaving() : \Miner
\Miner
closeWhere() : \Miner
\Miner
delete(string|false $table = false
) : \Miner
string
false
optional table name, default false
\Miner
distinct() : \Miner
\Miner
execute() : \PDOStatement | false
\PDOStatement
false
executed statement or false if failedfrom(string $table, string $alias = null
) : \Miner
string
table name
string
optional alias
\Miner
getAutoQuote(bool|null $override = null
) : bool
bool
null
value-specific override for convenience
bool
getDeleteString(bool $includeText = true
) : string
bool
optional include 'DELETE' text, default true
string
DELETE portion of the statementgetFrom() : string
string
FROM tablegetFromAlias() : string
string
FROM table aliasgetFromString(bool $includeText = true
) : string
bool
optional include 'FROM' text, default true
string
FROM portion of the statementgetGroupByString(bool $includeText = true
) : string
bool
optional include 'GROUP BY' text, default true
string
GROUP BY portion of the statementgetHavingPlaceholderValues() : array
array
HAVING placeholder valuesgetHavingString(bool $usePlaceholders= true
, bool $includeText= true
) : string
bool
optional use ? placeholders, default true
bool
optional include 'HAVING' text, default true
string
HAVING portion of the statementgetInsert() : string
string
INSERT tablegetInsertString(bool $includeText = true
) : string
bool
optional include 'INSERT' text, default true
string
INSERT portion of the statementgetJoinString() : string
string
JOIN portion of the statementgetLimit() : int | string
int
string
LIMIT on number of rows to returngetLimitOffset() : int | string
int
string
LIMIT row number to start atgetLimitString(bool $includeText = true
) : string
bool
optional include 'LIMIT' text, default true
string
LIMIT portion of the statementgetOptionsString(bool $includeTrailingSpace = false
) : string
bool
optional include space after options
string
execution options portion of the statementgetOrderByString(bool $includeText = true
) : string
bool
optional include 'ORDER BY' text, default true
string
ORDER BY portion of the statementgetPdoConnection() : \PDO | null
\PDO
null
getPlaceholderValues() : array
array
all placeholder valuesgetReplace() : string
string
REPLACE tablegetReplaceString(bool $includeText = true
) : string
bool
optional include 'REPLACE' text, default true
string
REPLACE portion of the statementgetSelectString(bool $includeText = true
) : string
bool
optional include 'SELECT' text, default true
string
SELECT portion of the statementgetSetPlaceholderValues() : array
array
SET placeholder valuesgetSetString(bool $usePlaceholders= true
, bool $includeText= true
) : string
bool
optional use ? placeholders, default true
bool
optional include 'SET' text, default true
string
SET portion of the statementgetStatement(bool $usePlaceholders = true
) : string
bool
optional use ? placeholders, default true
string
full SQL statementgetUpdate() : string
string
UPDATE tablegetUpdateString(bool $includeText = true
) : string
bool
optional include 'UPDATE' text, default true
string
UPDATE portion of the statementgetWherePlaceholderValues() : array
array
WHERE placeholder valuesgetWhereString(bool $usePlaceholders= true
, bool $includeText= true
) : string
bool
optional use ? placeholders, default true
bool
optional include 'WHERE' text, default true
string
WHERE portion of the statementgroupBy(string $column, string|null $order = null
) : \Miner
string
column name
string
null
optional order direction, default none
\Miner
having(string $column, mixed $value, string $operator= self::EQUALS
, string $connector= self::LOGICAL_AND
, bool|null $quote= null
) : \Miner
string
colum name
mixed
value
string
optional comparison operator, default =
string
optional logical connector, default AND
bool
null
optional auto-escape value, default to global
\Miner
havingBetween(string $column, mixed $min, mixed $max, string $connector= self::LOGICAL_AND
, bool|null $quote= null
) : \Miner
string
column name
mixed
minimum value
mixed
maximum value
string
optional logical connector, default AND
bool
null
optional auto-escape value, default to global
\Miner
havingIn(string $column, array $values, string $connector= self::LOGICAL_AND
, bool|null $quote= null
) : \Miner
string
column name
array
values
string
optional logical connector, default AND
bool
null
optional auto-escape value, default to global
\Miner
havingNotBetween(string $column, mixed $min, mixed $max, string $connector= self::LOGICAL_AND
, bool|null $quote= null
) : \Miner
string
column name
mixed
minimum value
mixed
maximum value
string
optional logical connector, default AND
bool
null
optional auto-escape value, default to global
\Miner
havingNotIn(string $column, array $values, string $connector= self::LOGICAL_AND
, bool|null $quote= null
) : \Miner
string
column name
array
values
string
optional logical connector, default AND
bool
null
optional auto-escape value, default to global
\Miner
innerJoin(string $table, string|array $criteria= null
, string $alias= null
) : \Miner
string
table name
string
array
optional ON criteria
string
optional alias
\Miner
insert(string $table) : \Miner
string
INSERT table
\Miner
isDelete() : bool
bool
whether this is a DELETE statementisInsert() : bool
bool
whether this is an INSERT statementisReplace() : bool
bool
whether this is a REPLACE statementisSelect() : bool
bool
whether this is a SELECT statementisUpdate() : bool
bool
whether this is an UPDATE statementjoin(string $table, string|array $criteria= null
, string $type= self::INNER_JOIN
, string $alias= null
) : \Miner
string
table name
string
array
optional ON criteria
string
optional type of join, default INNER JOIN
string
optional alias
\Miner
leftJoin(string $table, string|array $criteria= null
, string $alias= null
) : \Miner
string
table name
string
array
optional ON criteria
string
optional alias
\Miner
limit(int|string $limit, int|string $offset = 0
) : \Miner
int
string
number of rows to return
int
string
optional row number to start at, default 0
\Miner
mergeDeleteInto(\Miner $Miner) : \Miner
\Miner
to merge into
\Miner
mergeFromInto(\Miner $Miner) : \Miner
\Miner
to merge into
\Miner
mergeGroupByInto(\Miner $Miner) : \Miner
\Miner
to merge into
\Miner
mergeHavingInto(\Miner $Miner) : \Miner
\Miner
to merge into
\Miner
mergeInsertInto(\Miner $Miner) : \Miner
\Miner
to merge into
\Miner
mergeInto(\Miner $Miner, bool $overrideLimit = true
) : \Miner
\Miner
to merge into
bool
optional override limit, default true
\Miner
mergeJoinInto(\Miner $Miner) : \Miner
\Miner
to merge into
\Miner
mergeLimitInto(\Miner $Miner) : \Miner
\Miner
to merge into
\Miner
mergeOptionsInto(\Miner $Miner) : \Miner
\Miner
to merge into
\Miner
mergeOrderByInto(\Miner $Miner) : \Miner
\Miner
to merge into
\Miner
mergeReplaceInto(\Miner $Miner) : \Miner
\Miner
to merge into
\Miner
mergeSelectInto(\Miner $Miner) : \Miner
\Miner
to merge into
\Miner
mergeSetInto(\Miner $Miner) : \Miner
\Miner
to merge into
\Miner
mergeUpdateInto(\Miner $Miner) : \Miner
\Miner
to merge into
\Miner
mergeWhereInto(\Miner $Miner) : \Miner
\Miner
to merge into
\Miner
openHaving(string $connector = self::LOGICAL_AND
) : \Miner
string
optional logical connector, default AND
\Miner
openWhere(string $connector = self::LOGICAL_AND
) : \Miner
string
optional logical connector, default AND
\Miner
option(string $option) : \Miner
string
execution option to add
\Miner
orHaving(string $column, mixed $value, string $operator= self::EQUALS
, bool|null $quote= null
) : \Miner
string
colum name
mixed
value
string
optional comparison operator, default =
bool
null
optional auto-escape value, default to global
\Miner
orWhere(string $column, mixed $value, string $operator= self::EQUALS
, bool|null $quote= null
) : \Miner
string
colum name
mixed
value
string
optional comparison operator, default =
bool
null
optional auto-escape value, default to global
\Miner
orderBy(string $column, string $order = self::ORDER_BY_ASC
) : \Miner
string
column name
string
optional order direction, default ASC
\Miner
quote(mixed $value) : mixed | false
mixed
value to escape
mixed
false
escaped value or false if failedreplace(string $table) : \Miner
string
REPLACE table
\Miner
rightJoin(string $table, string|array $criteria= null
, string $alias= null
) : \Miner
string
table name
string
array
optional ON criteria
string
optional alias
\Miner
select(string $column, string $alias = null
) : \Miner
string
column name, table name, or expression
string
optional alias
\Miner
set(string|array $column, mixed|null $value= null
, bool|null $quote= null
) : \Miner
string
array
column name or array of columns => values
mixed
null
optional value for single column
bool
null
optional auto-escape value, default to global
\Miner
setAutoQuote(bool|null $autoQuote) : \Miner
bool
null
whether to automatically escape values
\Miner
setPdoConnection(\PDO|null $PdoConnection = null
) : \Miner
\PDO
null
optional PDO database connection
\Miner
update(string $table) : \Miner
string
UPDATE table
\Miner
values(array $values) : \Miner
array
columns => values
\Miner
where(string $column, mixed $value, string $operator= self::EQUALS
, string $connector= self::LOGICAL_AND
, bool|null $quote= null
) : \Miner
string
column name
mixed
value
string
optional comparison operator, default =
string
optional logical connector, default AND
bool
null
optional auto-escape value, default to global
\Miner
whereBetween(string $column, mixed $min, mixed $max, string $connector= self::LOGICAL_AND
, bool|null $quote= null
) : \Miner
string
column name
mixed
minimum value
mixed
maximum value
string
optional logical connector, default AND
bool
null
optional auto-escape value, default to global
\Miner
whereIn(string $column, array $values, string $connector= self::LOGICAL_AND
, bool|null $quote= null
) : \Miner
string
column name
array
values
string
optional logical connector, default AND
bool
null
optional auto-escape value, default to global
\Miner
whereNotBetween(string $column, mixed $min, mixed $max, string $connector= self::LOGICAL_AND
, bool|null $quote= null
) : \Miner
string
column name
mixed
minimum value
mixed
maximum value
string
optional logical connector, default AND
bool
null
optional auto-escape value, default to global
\Miner
whereNotIn(string $column, array $values, string $connector= self::LOGICAL_AND
, bool|null $quote= null
) : \Miner
string
column name
array
values
string
optional logical connector, default AND
bool
null
optional auto-escape value, default to global
\Miner
closeCriteria(array $criteria) : \Miner
array
WHERE or HAVING criteria
\Miner
criteria(array $criteria, string $column, mixed $value, string $operator= self::EQUALS
, string $connector= self::LOGICAL_AND
, bool|null $quote= null
) : \Miner
array
WHERE or HAVING criteria
string
column name
mixed
value
string
optional comparison operator, default =
string
optional logical connector, default AND
bool
null
optional auto-escape value, default to global
\Miner
criteriaBetween(array $criteria, string $column, mixed $min, mixed $max, string $connector= self::LOGICAL_AND
, bool|null $quote= null
) : \Miner
array
WHERE or HAVING criteria
string
column name
mixed
minimum value
mixed
maximum value
string
optional logical connector, default AND
bool
null
optional auto-escape value, default to global
\Miner
criteriaIn(array $criteria, string $column, array $values, string $connector= self::LOGICAL_AND
, bool|null $quote= null
) : \Miner
array
WHERE or HAVING criteria
string
column name
array
values
string
optional logical connector, default AND
bool
null
optional auto-escape value, default to global
\Miner
criteriaNotBetween(array $criteria, string $column, mixed $min, mixed $max, string $connector= self::LOGICAL_AND
, bool|null $quote= null
) : \Miner
array
WHERE or HAVING criteria
string
column name
mixed
minimum value
mixed
maximum value
string
optional logical connector, default AND
bool
null
optional auto-escape value, default to global
\Miner
criteriaNotIn(array $criteria, string $column, array $values, string $connector= self::LOGICAL_AND
, bool|null $quote= null
) : \Miner
array
WHERE or HAVING criteria
string
column name
array
values
string
optional logical connector, default AND
bool
null
optional auto-escape value, default to global
\Miner
getCriteriaString(array $criteria, bool $usePlaceholders= true
, array $placeholderValues= array()
) : string
array
WHERE or HAVING criteria
bool
optional use ? placeholders, default true
array
optional placeholder values array
string
WHERE or HAVING portion of the statementgetDeleteStatement(bool $usePlaceholders = true
) : string
bool
optional use ? placeholders, default true
string
full DELETE statementgetInsertStatement(bool $usePlaceholders = true
) : string
bool
optional use ? placeholders, default true
string
full INSERT statementgetJoinCriteriaUsingPreviousTable(int $joinIndex, string $table, string $column) : string
int
index of current join
string
current table name
string
current column name
string
ON join criteriagetReplaceStatement(bool $usePlaceholders = true
) : string
bool
optional use ? placeholders, default true
string
full REPLACE statementgetSelectStatement(bool $usePlaceholders = true
) : string
bool
optional use ? placeholders, default true
string
full SELECT statementgetUpdateStatement(bool $usePlaceholders = true
) : string
bool
optional use ? placeholders, default true
string
full UPDATE statementisDeleteTableFrom() : bool
bool
whether the delete table is FROMisJoinUnique(string $table, string $alias) : bool
string
table name
string
table alias
bool
whether the join table and alias is uniqueopenCriteria(array $criteria, string $connector = self::LOGICAL_AND
) : \Miner
array
WHERE or HAVING criteria
string
optional logical connector, default AND
\Miner
orCriteria(array $criteria, string $column, mixed $value, string $operator= self::EQUALS
, bool|null $quote= null
) : \Miner
array
WHERE or HAVING criteria
string
column name
mixed
value
string
optional comparison operator, default =
bool
null
optional auto-escape value, default to global
\Miner
$PdoConnection : \PDO | null
$autoQuote : bool | null
$delete : array | true
$from : array
$groupBy : array
$having : array
$havingPlaceholderValues : array
$insert : string
$join : array
$limit : array
$option : array
$orderBy : array
$replace : string
$select : array
$set : array
$setPlaceholderValues : array
$update : string
$where : array
$wherePlaceholderValues : array
BETWEEN = "BETWEEN"
BRACKET_CLOSE = ")"
BRACKET_OPEN = "("
EQUALS = "="
GREATER_THAN = ">"
GREATER_THAN_OR_EQUAL = ">="
ILIKE = "ILIKE"
IN = "IN"
INNER_JOIN = "INNER JOIN"
IS = "IS"
IS_NOT = "IS NOT"
LEFT_JOIN = "LEFT JOIN"
LESS_THAN = "<"
LESS_THAN_OR_EQUAL = "<="
LIKE = "LIKE"
LOGICAL_AND = "AND"
LOGICAL_OR = "OR"
NOT_BETWEEN = "NOT BETWEEN"
NOT_EQUALS = "!="
NOT_IN = "NOT IN"
NOT_LIKE = "NOT LIKE"
NOT_REGEX = "NOT REGEXP"
ORDER_BY_ASC = "ASC"
ORDER_BY_DESC = "DESC"
REGEX = "REGEXP"
RIGHT_JOIN = "RIGHT JOIN"