Builder
extends BaseBuilder
in package
Builder for MySQLi
Table of Contents
- $QBGroupBy : array<string|int, mixed>
- QB GROUP BY data
- $QBNoEscape : array<string|int, mixed>
- QB NO ESCAPE data
- $QBOrderBy : array<string|int, mixed>|null|string
- QB ORDER BY data
- $binds : array<string|int, mixed>
- Collects the named parameters and their values for later binding in the Query object.
- $bindsKeyCount : array<string|int, mixed>
- Collects the key count for named parameters in the Query object.
- $canLimitDeletes : bool
- Some databases, like SQLite, do not by default allow limiting of delete clauses.
- $canLimitWhereUpdates : bool
- Some databases do not by default allow limit update queries with WHERE.
- $countString : string
- COUNT string
- $db : BaseConnection
- A reference to the database connection.
- $escapeChar : string
- Identifier escape character
- $joinTypes : array<string|int, mixed>
- Tables relation types
- $QBDistinct : bool
- QB DISTINCT flag
- $QBFrom : array<string|int, mixed>
- QB FROM data
- $QBHaving : array<string|int, mixed>
- QB HAVING data
- $QBIgnore : bool
- Ignore data that cause certain exceptions, for example in case of duplicate keys.
- $QBJoin : array<string|int, mixed>
- QB JOIN data
- $QBKeys : array<string|int, mixed>
- QB keys
- $QBLimit : int|bool
- QB LIMIT data
- $QBOffset : int|bool
- QB OFFSET data
- $QBSelect : array<string|int, mixed>
- QB SELECT data
- $QBSet : array<string|int, mixed>
- QB data sets
- $QBWhere : array<string|int, mixed>
- QB WHERE data
- $QBWhereGroupCount : int
- QB WHERE group count
- $QBWhereGroupStarted : bool
- QB WHERE group started flag
- $randomKeyword : array<string|int, mixed>
- ORDER BY random keyword
- $resetDeleteData : bool
- Reset DELETE data flag
- $supportedIgnoreStatements : array<string|int, mixed>
- Specifies which sql statements support the ignore option.
- $tableName : string
- Name of the primary table for this instance.
- $testMode : bool
- Builder testing mode status.
- __construct() : mixed
- Constructor
- countAll() : int|string
- "Count All" query
- countAllResults() : int|string
- "Count All Results" query
- db() : ConnectionInterface|BaseConnection
- Returns the current database connection
- decrement() : bool
- Decrements a numeric column by the specified value.
- delete() : string|bool
- Delete
- distinct() : $this
- DISTINCT
- emptyTable() : bool|string
- Empty Table
- from() : $this
- From
- get() : ResultInterface|false
- Get
- getBinds() : array<string|int, mixed>
- Returns an array of bind values and their named parameters for binding in the Query object later.
- getCompiledDelete() : string
- Get DELETE query string
- getCompiledInsert() : string|bool
- Get INSERT query string
- getCompiledQBWhere() : array<string|int, mixed>
- Get compiled 'where' condition string
- getCompiledSelect() : string
- Get SELECT query string
- getCompiledUpdate() : string|bool
- Get UPDATE query string
- getSetData() : array<string|int, mixed>
- Returns the previously set() data, alternatively resetting it if needed.
- getTable() : string
- Gets the name of the primary table.
- getWhere() : ResultInterface
- Get_Where
- groupBy() : $this
- GROUP BY
- groupEnd() : $this
- Ends a query group
- groupStart() : $this
- Starts a query group.
- having() : $this
- HAVING
- havingGroupEnd() : $this
- Ends a query group for HAVING clause.
- havingGroupStart() : $this
- Starts a query group for HAVING clause.
- havingIn() : $this
- HAVING IN
- havingLike() : $this
- LIKE with HAVING clause
- havingNotIn() : $this
- HAVING NOT IN
- ignore() : $this
- Ignore
- increment() : bool
- Increments a numeric column by the specified value.
- insert() : Query|bool
- Insert
- insertBatch() : int|false
- Insert_Batch
- join() : $this
- JOIN
- like() : $this
- LIKE
- limit() : $this
- LIMIT
- notGroupStart() : $this
- Starts a query group, but NOTs the group
- notHavingGroupStart() : $this
- Starts a query group for HAVING clause, but NOTs the group.
- notHavingLike() : $this
- NOT LIKE with HAVING clause
- notLike() : $this
- NOT LIKE
- offset() : $this
- Sets the OFFSET value
- orderBy() : $this
- ORDER BY
- orGroupStart() : $this
- Starts a query group, but ORs the group
- orHaving() : $this
- OR HAVING
- orHavingGroupStart() : $this
- Starts a query group for HAVING clause, but ORs the group.
- orHavingIn() : $this
- OR HAVING IN
- orHavingLike() : $this
- OR LIKE with HAVING clause
- orHavingNotIn() : $this
- OR HAVING NOT IN
- orLike() : $this
- OR LIKE
- orNotGroupStart() : $this
- Starts a query group, but OR NOTs the group
- orNotHavingGroupStart() : $this
- Starts a query group for HAVING clause, but OR NOTs the group.
- orNotHavingLike() : $this
- OR NOT LIKE with HAVING clause
- orNotLike() : $this
- OR NOT LIKE
- orWhere() : $this
- OR WHERE
- orWhereIn() : $this
- OR WHERE IN
- orWhereNotIn() : $this
- OR WHERE NOT IN
- replace() : BaseResult|Query|string|false
- Replace
- resetQuery() : $this
- Reset Query Builder values.
- select() : $this
- Select
- selectAvg() : $this
- Select Average
- selectCount() : $this
- Select Count
- selectMax() : $this
- Select Max
- selectMin() : $this
- Select Min
- selectSum() : $this
- Select Sum
- set() : $this
- The "set" function.
- setInsertBatch() : $this|null
- The "setInsertBatch" function. Allows key/value pairs to be set for batch inserts
- setUpdateBatch() : $this|null
- The "setUpdateBatch" function. Allows key/value pairs to be set for batch updating
- testMode() : $this
- Sets a test mode status.
- truncate() : bool|string
- Truncate
- update() : bool
- UPDATE
- updateBatch() : mixed
- Update_Batch
- where() : $this
- WHERE
- whereIn() : $this
- WHERE IN
- whereNotIn() : $this
- WHERE NOT IN
- _delete() : string
- Delete statement
- _fromTables() : string
- FROM tables
- _insert() : string
- Insert statement
- _insertBatch() : string
- Insert batch statement
- _like() : $this
- Internal LIKE
- _like_statement() : string
- Platform independent LIKE statement builder.
- _limit() : string
- LIMIT string
- _replace() : string
- Replace statement
- _truncate() : string
- Truncate statement
- _update() : string
- Update statement
- _updateBatch() : string
- Update_Batch statement
- _whereIn() : $this
- Internal WHERE IN
- batchObjectToArray() : mixed
- Object to Array
- cleanClone() : $this
- Returns a clone of a Base Builder with reset query builder values.
- compileFinalQuery() : string
- Returns a finalized, compiled query string with the bindings inserted and prefixes swapped out.
- compileGroupBy() : string
- Compile GROUP BY
- compileIgnore() : string
- Compile Ignore Statement
- compileOrderBy() : string
- Compile ORDER BY
- compileSelect() : string
- Compile the SELECT statement
- compileWhereHaving() : string
- Compile WHERE, HAVING statements
- createAliasFromTable() : string
- Determines the alias name based on the table
- getOperator() : mixed
- Returns the SQL string operator
- groupEndPrepare() : $this
- Prepate a query group end.
- groupGetType() : string
- Group_get_type
- groupStartPrepare() : $this
- Prepate a query group start.
- hasOperator() : bool
- Tests whether the string has an SQL operator
- isLiteral() : bool
- Is literal
- maxMinAvgSum() : $this
- SELECT [MAX|MIN|AVG|SUM|COUNT]()
- objectToArray() : mixed
- Object to Array
- resetRun() : void
- Resets the query builder values. Called by the get() function
- resetSelect() : mixed
- Resets the query builder values. Called by the get() function
- resetWrite() : mixed
- Resets the query builder "write" values.
- setBind() : string
- Stores a bind value after ensuring that it's unique.
- trackAliases() : string|void
- Track Aliases
- validateInsert() : bool
- Validate Insert
- validateUpdate() : bool
- Validate Update
- whereHaving() : $this
- WHERE, HAVING
Properties
$QBGroupBy
QB GROUP BY data
public
array<string|int, mixed>
$QBGroupBy
= []
$QBNoEscape
QB NO ESCAPE data
public
array<string|int, mixed>
$QBNoEscape
= []
$QBOrderBy
QB ORDER BY data
public
array<string|int, mixed>|null|string
$QBOrderBy
= []
$binds
Collects the named parameters and their values for later binding in the Query object.
protected
array<string|int, mixed>
$binds
= []
$bindsKeyCount
Collects the key count for named parameters in the Query object.
protected
array<string|int, mixed>
$bindsKeyCount
= []
$canLimitDeletes
Some databases, like SQLite, do not by default allow limiting of delete clauses.
protected
bool
$canLimitDeletes
= true
$canLimitWhereUpdates
Some databases do not by default allow limit update queries with WHERE.
protected
bool
$canLimitWhereUpdates
= true
$countString
COUNT string
protected
string
$countString
= 'SELECT COUNT(*) AS '
Tags
$db
A reference to the database connection.
protected
BaseConnection
$db
$escapeChar
Identifier escape character
protected
string
$escapeChar
= '`'
$joinTypes
Tables relation types
protected
array<string|int, mixed>
$joinTypes
= ['LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER']
$QBDistinct
QB DISTINCT flag
protected
bool
$QBDistinct
= false
$QBFrom
QB FROM data
protected
array<string|int, mixed>
$QBFrom
= []
$QBHaving
QB HAVING data
protected
array<string|int, mixed>
$QBHaving
= []
$QBIgnore
Ignore data that cause certain exceptions, for example in case of duplicate keys.
protected
bool
$QBIgnore
= false
$QBJoin
QB JOIN data
protected
array<string|int, mixed>
$QBJoin
= []
$QBKeys
QB keys
protected
array<string|int, mixed>
$QBKeys
= []
$QBLimit
QB LIMIT data
protected
int|bool
$QBLimit
= false
$QBOffset
QB OFFSET data
protected
int|bool
$QBOffset
= false
$QBSelect
QB SELECT data
protected
array<string|int, mixed>
$QBSelect
= []
$QBSet
QB data sets
protected
array<string|int, mixed>
$QBSet
= []
$QBWhere
QB WHERE data
protected
array<string|int, mixed>
$QBWhere
= []
$QBWhereGroupCount
QB WHERE group count
protected
int
$QBWhereGroupCount
= 0
$QBWhereGroupStarted
QB WHERE group started flag
protected
bool
$QBWhereGroupStarted
= false
$randomKeyword
ORDER BY random keyword
protected
array<string|int, mixed>
$randomKeyword
= ['RAND()', 'RAND(%d)']
$resetDeleteData
Reset DELETE data flag
protected
bool
$resetDeleteData
= false
$supportedIgnoreStatements
Specifies which sql statements support the ignore option.
protected
array<string|int, mixed>
$supportedIgnoreStatements
= ['update' => 'IGNORE', 'insert' => 'IGNORE', 'delete' => 'IGNORE']
$tableName
Name of the primary table for this instance.
protected
string
$tableName
Tracked separately because $QBFrom gets escaped and prefixed.
$testMode
Builder testing mode status.
protected
bool
$testMode
= false
Methods
__construct()
Constructor
public
__construct(string|array<string|int, mixed> $tableName, ConnectionInterface &$db[, array<string|int, mixed> $options = null ]) : mixed
Parameters
- $tableName : string|array<string|int, mixed>
- $db : ConnectionInterface
- $options : array<string|int, mixed> = null
Tags
Return values
mixed —countAll()
"Count All" query
public
countAll([bool $reset = true ]) : int|string
Generates a platform-specific query string that counts all records in the particular table
Parameters
- $reset : bool = true
-
Are we want to clear query builder values?
Return values
int|string —when $test = true
countAllResults()
"Count All Results" query
public
countAllResults([bool $reset = true ]) : int|string
Generates a platform-specific query string that counts all records returned by an Query Builder query.
Parameters
- $reset : bool = true
Return values
int|string —when $test = true
db()
Returns the current database connection
public
db() : ConnectionInterface|BaseConnection
Return values
ConnectionInterface|BaseConnection —decrement()
Decrements a numeric column by the specified value.
public
decrement(string $column[, int $value = 1 ]) : bool
Parameters
- $column : string
- $value : int = 1
Return values
bool —delete()
Delete
public
delete([mixed $where = '' ][, int $limit = null ][, bool $resetData = true ]) : string|bool
Compiles a delete string and runs the query
Parameters
- $where : mixed = ''
-
The where clause
- $limit : int = null
-
The limit clause
- $resetData : bool = true
Tags
Return values
string|bool —distinct()
DISTINCT
public
distinct([bool $val = true ]) : $this
Sets a flag which tells the query string compiler to add DISTINCT
Parameters
- $val : bool = true
Return values
$this —emptyTable()
Empty Table
public
emptyTable() : bool|string
Compiles a delete string and runs "DELETE FROM table"
Return values
bool|string —TRUE on success, FALSE on failure, string on testMode
from()
From
public
from(mixed $from[, bool $overwrite = false ]) : $this
Generates the FROM portion of the query
Parameters
- $from : mixed
-
can be a string or array
- $overwrite : bool = false
-
Should we remove the first table existing?
Return values
$this —get()
Get
public
get([int $limit = null ], int $offset[, bool $reset = true ]) : ResultInterface|false
Compiles the select statement based on the other functions called and runs the query
Parameters
- $limit : int = null
-
The limit clause
- $offset : int
-
The offset clause
- $reset : bool = true
-
Are we want to clear query builder values?
Return values
ResultInterface|false —getBinds()
Returns an array of bind values and their named parameters for binding in the Query object later.
public
getBinds() : array<string|int, mixed>
Return values
array<string|int, mixed> —getCompiledDelete()
Get DELETE query string
public
getCompiledDelete([bool $reset = true ]) : string
Compiles a delete query string and returns the sql
Parameters
- $reset : bool = true
-
TRUE: reset QB values; FALSE: leave QB values alone
Return values
string —getCompiledInsert()
Get INSERT query string
public
getCompiledInsert([bool $reset = true ]) : string|bool
Compiles an insert query and returns the sql
Parameters
- $reset : bool = true
-
TRUE: reset QB values; FALSE: leave QB values alone
Tags
Return values
string|bool —getCompiledQBWhere()
Get compiled 'where' condition string
public
getCompiledQBWhere() : array<string|int, mixed>
Compiles the set conditions and returns the sql statement
Return values
array<string|int, mixed> —getCompiledSelect()
Get SELECT query string
public
getCompiledSelect([bool $reset = true ]) : string
Compiles a SELECT query string and returns the sql.
Parameters
- $reset : bool = true
-
TRUE: resets QB values; FALSE: leave QB values alone
Return values
string —getCompiledUpdate()
Get UPDATE query string
public
getCompiledUpdate([bool $reset = true ]) : string|bool
Compiles an update query and returns the sql
Parameters
- $reset : bool = true
-
TRUE: reset QB values; FALSE: leave QB values alone
Return values
string|bool —getSetData()
Returns the previously set() data, alternatively resetting it if needed.
public
getSetData([bool $clean = false ]) : array<string|int, mixed>
Parameters
- $clean : bool = false
Return values
array<string|int, mixed> —getTable()
Gets the name of the primary table.
public
getTable() : string
Return values
string —getWhere()
Get_Where
public
getWhere([string|array<string|int, mixed> $where = null ][, int $limit = null ], int $offset[, bool $reset = true ]) : ResultInterface
Allows the where clause, limit and offset to be added directly
Parameters
- $where : string|array<string|int, mixed> = null
-
Where condition
- $limit : int = null
-
Limit value
- $offset : int
-
Offset value
- $reset : bool = true
-
Are we want to clear query builder values?
Return values
ResultInterface —groupBy()
GROUP BY
public
groupBy(string|array<string|int, mixed> $by[, bool $escape = null ]) : $this
Parameters
- $by : string|array<string|int, mixed>
- $escape : bool = null
Return values
$this —groupEnd()
Ends a query group
public
groupEnd() : $this
Return values
$this —groupStart()
Starts a query group.
public
groupStart() : $this
Return values
$this —having()
HAVING
public
having(string|array<string|int, mixed> $key[, mixed $value = null ][, bool $escape = null ]) : $this
Separates multiple calls with 'AND'.
Parameters
- $key : string|array<string|int, mixed>
- $value : mixed = null
- $escape : bool = null
Return values
$this —havingGroupEnd()
Ends a query group for HAVING clause.
public
havingGroupEnd() : $this
Return values
$this —havingGroupStart()
Starts a query group for HAVING clause.
public
havingGroupStart() : $this
Return values
$this —havingIn()
HAVING IN
public
havingIn([string $key = null ][, array<string|int, mixed>|string|Closure $values = null ][, bool $escape = null ]) : $this
Generates a HAVING field IN('item', 'item') SQL query, joined with 'AND' if appropriate.
Parameters
- $key : string = null
-
The field to search
- $values : array<string|int, mixed>|string|Closure = null
-
The values searched on, or anonymous function with subquery
- $escape : bool = null
Return values
$this —havingLike()
LIKE with HAVING clause
public
havingLike(mixed $field[, string $match = '' ][, string $side = 'both' ][, bool $escape = null ][, bool $insensitiveSearch = false ]) : $this
Generates a %LIKE% portion of the query. Separates multiple calls with 'AND'.
Parameters
- $field : mixed
- $match : string = ''
- $side : string = 'both'
- $escape : bool = null
- $insensitiveSearch : bool = false
Return values
$this —havingNotIn()
HAVING NOT IN
public
havingNotIn([string $key = null ][, array<string|int, mixed>|string|Closure $values = null ][, bool $escape = null ]) : $this
Generates a HAVING field NOT IN('item', 'item') SQL query, joined with 'AND' if appropriate.
Parameters
- $key : string = null
-
The field to search
- $values : array<string|int, mixed>|string|Closure = null
-
The values searched on, or anonymous function with subquery
- $escape : bool = null
Return values
$this —ignore()
Ignore
public
ignore([bool $ignore = true ]) : $this
Set ignore Flag for next insert, update or delete query.
Parameters
- $ignore : bool = true
Return values
$this —increment()
Increments a numeric column by the specified value.
public
increment(string $column[, int $value = 1 ]) : bool
Parameters
- $column : string
- $value : int = 1
Return values
bool —insert()
Insert
public
insert([array<string|int, mixed> $set = null ][, bool $escape = null ]) : Query|bool
Compiles an insert string and runs the query
Parameters
- $set : array<string|int, mixed> = null
-
An associative array of insert values
- $escape : bool = null
-
Whether to escape values and identifiers
Tags
Return values
Query|bool —insertBatch()
Insert_Batch
public
insertBatch([array<string|int, mixed> $set = null ][, bool $escape = null ][, int $batchSize = 100 ]) : int|false
Compiles batch insert strings and runs the queries
Parameters
- $set : array<string|int, mixed> = null
-
An associative array of insert values
- $escape : bool = null
-
Whether to escape values and identifiers
- $batchSize : int = 100
-
Batch size
Tags
Return values
int|false —Number of rows inserted or FALSE on failure
join()
JOIN
public
join(string $table, string $cond[, string $type = '' ][, bool $escape = null ]) : $this
Generates the JOIN portion of the query
Parameters
- $table : string
- $cond : string
-
The join condition
- $type : string = ''
-
The type of join
- $escape : bool = null
-
Whether not to try to escape identifiers
Return values
$this —like()
LIKE
public
like(mixed $field[, string $match = '' ][, string $side = 'both' ][, bool $escape = null ][, bool $insensitiveSearch = false ]) : $this
Generates a %LIKE% portion of the query. Separates multiple calls with 'AND'.
Parameters
- $field : mixed
- $match : string = ''
- $side : string = 'both'
- $escape : bool = null
- $insensitiveSearch : bool = false
-
IF true, will force a case-insensitive search
Return values
$this —limit()
LIMIT
public
limit([int|null $value = null ], int|null $offset) : $this
Parameters
- $value : int|null = null
-
LIMIT value
- $offset : int|null
-
OFFSET value
Return values
$this —notGroupStart()
Starts a query group, but NOTs the group
public
notGroupStart() : $this
Return values
$this —notHavingGroupStart()
Starts a query group for HAVING clause, but NOTs the group.
public
notHavingGroupStart() : $this
Return values
$this —notHavingLike()
NOT LIKE with HAVING clause
public
notHavingLike(mixed $field[, string $match = '' ][, string $side = 'both' ][, bool $escape = null ][, bool $insensitiveSearch = false ]) : $this
Generates a NOT LIKE portion of the query. Separates multiple calls with 'AND'.
Parameters
- $field : mixed
- $match : string = ''
- $side : string = 'both'
- $escape : bool = null
- $insensitiveSearch : bool = false
Return values
$this —notLike()
NOT LIKE
public
notLike(mixed $field[, string $match = '' ][, string $side = 'both' ][, bool $escape = null ][, bool $insensitiveSearch = false ]) : $this
Generates a NOT LIKE portion of the query. Separates multiple calls with 'AND'.
Parameters
- $field : mixed
- $match : string = ''
- $side : string = 'both'
- $escape : bool = null
- $insensitiveSearch : bool = false
-
IF true, will force a case-insensitive search
Return values
$this —offset()
Sets the OFFSET value
public
offset(int $offset) : $this
Parameters
- $offset : int
-
OFFSET value
Return values
$this —orderBy()
ORDER BY
public
orderBy(string $orderBy[, string $direction = '' ][, bool $escape = null ]) : $this
Parameters
- $orderBy : string
- $direction : string = ''
-
ASC, DESC or RANDOM
- $escape : bool = null
Return values
$this —orGroupStart()
Starts a query group, but ORs the group
public
orGroupStart() : $this
Return values
$this —orHaving()
OR HAVING
public
orHaving(string|array<string|int, mixed> $key[, mixed $value = null ][, bool $escape = null ]) : $this
Separates multiple calls with 'OR'.
Parameters
- $key : string|array<string|int, mixed>
- $value : mixed = null
- $escape : bool = null
Return values
$this —orHavingGroupStart()
Starts a query group for HAVING clause, but ORs the group.
public
orHavingGroupStart() : $this
Return values
$this —orHavingIn()
OR HAVING IN
public
orHavingIn([string $key = null ][, array<string|int, mixed>|string|Closure $values = null ][, bool $escape = null ]) : $this
Generates a HAVING field IN('item', 'item') SQL query, joined with 'OR' if appropriate.
Parameters
- $key : string = null
-
The field to search
- $values : array<string|int, mixed>|string|Closure = null
-
The values searched on, or anonymous function with subquery
- $escape : bool = null
Return values
$this —orHavingLike()
OR LIKE with HAVING clause
public
orHavingLike(mixed $field[, string $match = '' ][, string $side = 'both' ][, bool $escape = null ][, bool $insensitiveSearch = false ]) : $this
Generates a %LIKE% portion of the query. Separates multiple calls with 'OR'.
Parameters
- $field : mixed
- $match : string = ''
- $side : string = 'both'
- $escape : bool = null
- $insensitiveSearch : bool = false
Return values
$this —orHavingNotIn()
OR HAVING NOT IN
public
orHavingNotIn([string $key = null ][, array<string|int, mixed>|string|Closure $values = null ][, bool $escape = null ]) : $this
Generates a HAVING field NOT IN('item', 'item') SQL query, joined with 'OR' if appropriate.
Parameters
- $key : string = null
-
The field to search
- $values : array<string|int, mixed>|string|Closure = null
-
The values searched on, or anonymous function with subquery
- $escape : bool = null
Return values
$this —orLike()
OR LIKE
public
orLike(mixed $field[, string $match = '' ][, string $side = 'both' ][, bool $escape = null ][, bool $insensitiveSearch = false ]) : $this
Generates a %LIKE% portion of the query. Separates multiple calls with 'OR'.
Parameters
- $field : mixed
- $match : string = ''
- $side : string = 'both'
- $escape : bool = null
- $insensitiveSearch : bool = false
-
IF true, will force a case-insensitive search
Return values
$this —orNotGroupStart()
Starts a query group, but OR NOTs the group
public
orNotGroupStart() : $this
Return values
$this —orNotHavingGroupStart()
Starts a query group for HAVING clause, but OR NOTs the group.
public
orNotHavingGroupStart() : $this
Return values
$this —orNotHavingLike()
OR NOT LIKE with HAVING clause
public
orNotHavingLike(mixed $field[, string $match = '' ][, string $side = 'both' ][, bool $escape = null ][, bool $insensitiveSearch = false ]) : $this
Generates a NOT LIKE portion of the query. Separates multiple calls with 'OR'.
Parameters
- $field : mixed
- $match : string = ''
- $side : string = 'both'
- $escape : bool = null
- $insensitiveSearch : bool = false
Return values
$this —orNotLike()
OR NOT LIKE
public
orNotLike(mixed $field[, string $match = '' ][, string $side = 'both' ][, bool $escape = null ][, bool $insensitiveSearch = false ]) : $this
Generates a NOT LIKE portion of the query. Separates multiple calls with 'OR'.
Parameters
- $field : mixed
- $match : string = ''
- $side : string = 'both'
- $escape : bool = null
- $insensitiveSearch : bool = false
-
IF true, will force a case-insensitive search
Return values
$this —orWhere()
OR WHERE
public
orWhere(mixed $key[, mixed $value = null ][, bool $escape = null ]) : $this
Generates the WHERE portion of the query. Separates multiple calls with 'OR'.
Parameters
- $key : mixed
- $value : mixed = null
- $escape : bool = null
Return values
$this —orWhereIn()
OR WHERE IN
public
orWhereIn([string $key = null ][, array<string|int, mixed>|string|Closure $values = null ][, bool $escape = null ]) : $this
Generates a WHERE field IN('item', 'item') SQL query, joined with 'OR' if appropriate.
Parameters
- $key : string = null
-
The field to search
- $values : array<string|int, mixed>|string|Closure = null
-
The values searched on, or anonymous function with subquery
- $escape : bool = null
Return values
$this —orWhereNotIn()
OR WHERE NOT IN
public
orWhereNotIn([string $key = null ][, array<string|int, mixed>|string|Closure $values = null ][, bool $escape = null ]) : $this
Generates a WHERE field NOT IN('item', 'item') SQL query, joined with 'OR' if appropriate.
Parameters
- $key : string = null
-
The field to search
- $values : array<string|int, mixed>|string|Closure = null
-
The values searched on, or anonymous function with subquery
- $escape : bool = null
Return values
$this —replace()
Replace
public
replace([array<string|int, mixed> $set = null ]) : BaseResult|Query|string|false
Compiles an replace into string and runs the query
Parameters
- $set : array<string|int, mixed> = null
-
An associative array of insert values
Tags
Return values
BaseResult|Query|string|false —resetQuery()
Reset Query Builder values.
public
resetQuery() : $this
Publicly-visible method to reset the QB values.
Return values
$this —select()
Select
public
select([string|array<string|int, mixed> $select = '*' ][, bool $escape = null ]) : $this
Generates the SELECT portion of the query
Parameters
- $select : string|array<string|int, mixed> = '*'
- $escape : bool = null
Return values
$this —selectAvg()
Select Average
public
selectAvg([string $select = '' ][, string $alias = '' ]) : $this
Generates a SELECT AVG(field) portion of a query
Parameters
- $select : string = ''
-
The field
- $alias : string = ''
-
An alias
Return values
$this —selectCount()
Select Count
public
selectCount([string $select = '' ][, string $alias = '' ]) : $this
Generates a SELECT COUNT(field) portion of a query
Parameters
- $select : string = ''
-
The field
- $alias : string = ''
-
An alias
Return values
$this —selectMax()
Select Max
public
selectMax([string $select = '' ][, string $alias = '' ]) : $this
Generates a SELECT MAX(field) portion of a query
Parameters
- $select : string = ''
-
The field
- $alias : string = ''
-
An alias
Return values
$this —selectMin()
Select Min
public
selectMin([string $select = '' ][, string $alias = '' ]) : $this
Generates a SELECT MIN(field) portion of a query
Parameters
- $select : string = ''
-
The field
- $alias : string = ''
-
An alias
Return values
$this —selectSum()
Select Sum
public
selectSum([string $select = '' ][, string $alias = '' ]) : $this
Generates a SELECT SUM(field) portion of a query
Parameters
- $select : string = ''
-
The field
- $alias : string = ''
-
An alias
Return values
$this —set()
The "set" function.
public
set(string|array<string|int, mixed>|object $key[, string $value = '' ][, bool $escape = null ]) : $this
Allows key/value pairs to be set for insert(), update() or replace().
Parameters
- $key : string|array<string|int, mixed>|object
-
Field name, or an array of field/value pairs
- $value : string = ''
-
Field value, if $key is a single field
- $escape : bool = null
-
Whether to escape values and identifiers
Return values
$this —setInsertBatch()
The "setInsertBatch" function. Allows key/value pairs to be set for batch inserts
public
setInsertBatch(mixed $key[, string $value = '' ][, bool $escape = null ]) : $this|null
Parameters
- $key : mixed
- $value : string = ''
- $escape : bool = null
Return values
$this|null —setUpdateBatch()
The "setUpdateBatch" function. Allows key/value pairs to be set for batch updating
public
setUpdateBatch(array<string|int, mixed>|object $key[, string $index = '' ][, bool $escape = null ]) : $this|null
Parameters
- $key : array<string|int, mixed>|object
- $index : string = ''
- $escape : bool = null
Tags
Return values
$this|null —testMode()
Sets a test mode status.
public
testMode([bool $mode = true ]) : $this
Parameters
- $mode : bool = true
-
Mode to set
Return values
$this —truncate()
Truncate
public
truncate() : bool|string
Compiles a truncate string and runs the query If the database does not support the truncate() command This function maps to "DELETE FROM table"
Return values
bool|string —TRUE on success, FALSE on failure, string on testMode
update()
UPDATE
public
update([array<string|int, mixed> $set = null ][, mixed $where = null ][, int $limit = null ]) : bool
Compiles an update string and runs the query.
Parameters
- $set : array<string|int, mixed> = null
-
An associative array of update values
- $where : mixed = null
- $limit : int = null
Tags
Return values
bool —TRUE on success, FALSE on failure
updateBatch()
Update_Batch
public
updateBatch([array<string|int, mixed> $set = null ][, string $index = null ][, int $batchSize = 100 ]) : mixed
Compiles an update string and runs the query
Parameters
- $set : array<string|int, mixed> = null
-
An associative array of update values
- $index : string = null
-
The where key
- $batchSize : int = 100
-
The size of the batch to run
Tags
Return values
mixed —Number of rows affected, SQL string, or FALSE on failure
where()
WHERE
public
where(mixed $key[, mixed $value = null ][, bool $escape = null ]) : $this
Generates the WHERE portion of the query. Separates multiple calls with 'AND'.
Parameters
- $key : mixed
- $value : mixed = null
- $escape : bool = null
Return values
$this —whereIn()
WHERE IN
public
whereIn([string $key = null ][, array<string|int, mixed>|string|Closure $values = null ][, bool $escape = null ]) : $this
Generates a WHERE field IN('item', 'item') SQL query, joined with 'AND' if appropriate.
Parameters
- $key : string = null
-
The field to search
- $values : array<string|int, mixed>|string|Closure = null
-
The values searched on, or anonymous function with subquery
- $escape : bool = null
Return values
$this —whereNotIn()
WHERE NOT IN
public
whereNotIn([string $key = null ][, array<string|int, mixed>|string|Closure $values = null ][, bool $escape = null ]) : $this
Generates a WHERE field NOT IN('item', 'item') SQL query, joined with 'AND' if appropriate.
Parameters
- $key : string = null
-
The field to search
- $values : array<string|int, mixed>|string|Closure = null
-
The values searched on, or anonymous function with subquery
- $escape : bool = null
Return values
$this —_delete()
Delete statement
protected
_delete(string $table) : string
Generates a platform-specific delete string from the supplied data
Parameters
- $table : string
-
The table name
Return values
string —_fromTables()
FROM tables
protected
_fromTables() : string
Groups tables in FROM clauses if needed, so there is no confusion about operator precedence.
Note: This is only used (and overridden) by MySQL.
Return values
string —_insert()
Insert statement
protected
_insert(string $table, array<string|int, mixed> $keys, array<string|int, mixed> $unescapedKeys) : string
Generates a platform-specific insert string from the supplied data
Parameters
- $table : string
-
The table name
- $keys : array<string|int, mixed>
-
The insert keys
- $unescapedKeys : array<string|int, mixed>
-
The insert values
Return values
string —_insertBatch()
Insert batch statement
protected
_insertBatch(string $table, array<string|int, mixed> $keys, array<string|int, mixed> $values) : string
Generates a platform-specific insert string from the supplied data.
Parameters
- $table : string
-
Table name
- $keys : array<string|int, mixed>
-
INSERT keys
- $values : array<string|int, mixed>
-
INSERT values
Return values
string —_like()
Internal LIKE
protected
_like(mixed $field[, string $match = '' ][, string $type = 'AND ' ][, string $side = 'both' ][, string $not = '' ][, bool $escape = null ][, bool $insensitiveSearch = false ][, string $clause = 'QBWhere' ]) : $this
Parameters
- $field : mixed
- $match : string = ''
- $type : string = 'AND '
- $side : string = 'both'
- $not : string = ''
- $escape : bool = null
- $insensitiveSearch : bool = false
-
IF true, will force a case-insensitive search
- $clause : string = 'QBWhere'
-
(Internal use only)
Tags
Return values
$this —_like_statement()
Platform independent LIKE statement builder.
protected
_like_statement(string|null $prefix, string $column, string|null $not, string $bind[, bool $insensitiveSearch = false ]) : string
Parameters
- $prefix : string|null
- $column : string
- $not : string|null
- $bind : string
- $insensitiveSearch : bool = false
Return values
string —$like_statement
_limit()
LIMIT string
protected
_limit(string $sql[, bool $offsetIgnore = false ]) : string
Generates a platform-specific LIMIT clause.
Parameters
- $sql : string
-
SQL Query
- $offsetIgnore : bool = false
Return values
string —_replace()
Replace statement
protected
_replace(string $table, array<string|int, mixed> $keys, array<string|int, mixed> $values) : string
Generates a platform-specific replace string from the supplied data
Parameters
- $table : string
-
The table name
- $keys : array<string|int, mixed>
-
The insert keys
- $values : array<string|int, mixed>
-
The insert values
Return values
string —_truncate()
Truncate statement
protected
_truncate(string $table) : string
Generates a platform-specific truncate string from the supplied data
If the database does not support the truncate() command, then this method maps to 'DELETE FROM table'
Parameters
- $table : string
-
The table name
Return values
string —_update()
Update statement
protected
_update(string $table, array<string|int, mixed> $values) : string
Generates a platform-specific update string from the supplied data
Parameters
- $table : string
-
the Table name
- $values : array<string|int, mixed>
-
the Update data
Return values
string —_updateBatch()
Update_Batch statement
protected
_updateBatch(string $table, array<string|int, mixed> $values, string $index) : string
Generates a platform-specific batch update string from the supplied data
Parameters
- $table : string
-
Table name
- $values : array<string|int, mixed>
-
Update data
- $index : string
-
WHERE key
Return values
string —_whereIn()
Internal WHERE IN
protected
_whereIn([string $key = null ][, array<string|int, mixed>|Closure|null $values = null ][, bool $not = false ][, string $type = 'AND ' ][, bool $escape = null ][, string $clause = 'QBWhere' ]) : $this
Parameters
- $key : string = null
-
The field to search
- $values : array<string|int, mixed>|Closure|null = null
-
The values searched on, or anonymous function with subquery
- $not : bool = false
-
If the statement would be IN or NOT IN
- $type : string = 'AND '
- $escape : bool = null
- $clause : string = 'QBWhere'
-
(Internal use only)
Tags
Return values
$this —batchObjectToArray()
Object to Array
protected
batchObjectToArray(mixed $object) : mixed
Takes an object as input and converts the class variables to array key/vals
Parameters
- $object : mixed
Return values
mixed —cleanClone()
Returns a clone of a Base Builder with reset query builder values.
protected
cleanClone() : $this
Return values
$this —compileFinalQuery()
Returns a finalized, compiled query string with the bindings inserted and prefixes swapped out.
protected
compileFinalQuery(string $sql) : string
Parameters
- $sql : string
Return values
string —compileGroupBy()
Compile GROUP BY
protected
compileGroupBy() : string
Escapes identifiers in GROUP BY statements at execution time.
Required so that aliases are tracked properly, regardless of whether groupBy() is called prior to from(), join() and prefixTable is added only if needed.
Return values
string —SQL statement
compileIgnore()
Compile Ignore Statement
protected
compileIgnore(string $statement) : string
Checks if the ignore option is supported by the Database Driver for the specific statement.
Parameters
- $statement : string
Return values
string —compileOrderBy()
Compile ORDER BY
protected
compileOrderBy() : string
Escapes identifiers in ORDER BY statements at execution time.
Required so that aliases are tracked properly, regardless of whether orderBy() is called prior to from(), join() and prefixTable is added only if needed.
Return values
string —SQL statement
compileSelect()
Compile the SELECT statement
protected
compileSelect([mixed $selectOverride = false ]) : string
Generates a query string based on which functions were used. Should not be called directly.
Parameters
- $selectOverride : mixed = false
Return values
string —compileWhereHaving()
Compile WHERE, HAVING statements
protected
compileWhereHaving(string $qbKey) : string
Escapes identifiers in WHERE and HAVING statements at execution time.
Required so that aliases are tracked properly, regardless of whether where(), orWhere(), having(), orHaving are called prior to from(), join() and prefixTable is added only if needed.
Parameters
- $qbKey : string
-
'QBWhere' or 'QBHaving'
Return values
string —SQL statement
createAliasFromTable()
Determines the alias name based on the table
protected
createAliasFromTable(string $item) : string
Parameters
- $item : string
Return values
string —getOperator()
Returns the SQL string operator
protected
getOperator(string $str[, bool $list = false ]) : mixed
Parameters
- $str : string
- $list : bool = false
Return values
mixed —groupEndPrepare()
Prepate a query group end.
protected
groupEndPrepare([string $clause = 'QBWhere' ]) : $this
Parameters
- $clause : string = 'QBWhere'
Return values
$this —groupGetType()
Group_get_type
protected
groupGetType(string $type) : string
Parameters
- $type : string
Tags
Return values
string —groupStartPrepare()
Prepate a query group start.
protected
groupStartPrepare([string $not = '' ][, string $type = 'AND ' ][, string $clause = 'QBWhere' ]) : $this
Parameters
- $not : string = ''
- $type : string = 'AND '
- $clause : string = 'QBWhere'
Return values
$this —hasOperator()
Tests whether the string has an SQL operator
protected
hasOperator(string $str) : bool
Parameters
- $str : string
Return values
bool —isLiteral()
Is literal
protected
isLiteral(string $str) : bool
Determines if a string represents a literal value or a field name
Parameters
- $str : string
Return values
bool —maxMinAvgSum()
SELECT [MAX|MIN|AVG|SUM|COUNT]()
protected
maxMinAvgSum([string $select = '' ][, string $alias = '' ][, string $type = 'MAX' ]) : $this
Parameters
- $select : string = ''
-
Field name
- $alias : string = ''
- $type : string = 'MAX'
Tags
Return values
$this —objectToArray()
Object to Array
protected
objectToArray(mixed $object) : mixed
Takes an object as input and converts the class variables to array key/vals
Parameters
- $object : mixed
Return values
mixed —resetRun()
Resets the query builder values. Called by the get() function
protected
resetRun(array<string|int, mixed> $qbResetItems) : void
Parameters
- $qbResetItems : array<string|int, mixed>
-
An array of fields to reset
Return values
void —resetSelect()
Resets the query builder values. Called by the get() function
protected
resetSelect() : mixed
Return values
mixed —resetWrite()
Resets the query builder "write" values.
protected
resetWrite() : mixed
Called by the insert() update() insertBatch() updateBatch() and delete() functions
Return values
mixed —setBind()
Stores a bind value after ensuring that it's unique.
protected
setBind(string $key[, mixed $value = null ][, bool $escape = true ]) : string
While it might be nicer to have named keys for our binds array with PHP 7+ we get a huge memory/performance gain with indexed arrays instead, so lets take advantage of that here.
Parameters
- $key : string
- $value : mixed = null
- $escape : bool = true
Return values
string —trackAliases()
Track Aliases
protected
trackAliases(string|array<string|int, mixed> $table) : string|void
Used to track SQL statements written with aliased tables.
Parameters
- $table : string|array<string|int, mixed>
-
The table to inspect
Return values
string|void —validateInsert()
Validate Insert
protected
validateInsert() : bool
This method is used by both insert() and getCompiledInsert() to validate that the there data is actually being set and that table has been chosen to be inserted into.
Tags
Return values
bool —validateUpdate()
Validate Update
protected
validateUpdate() : bool
This method is used by both update() and getCompiledUpdate() to validate that data is actually being set and that a table has been chosen to be update.
Tags
Return values
bool —whereHaving()
WHERE, HAVING
protected
whereHaving(string $qbKey, mixed $key[, mixed $value = null ][, string $type = 'AND ' ][, bool $escape = null ]) : $this
Parameters
- $qbKey : string
-
'QBWhere' or 'QBHaving'
- $key : mixed
- $value : mixed = null
- $type : string = 'AND '
- $escape : bool = null