CodeIgniter v4.5 API

BaseBuilder
in package
uses ConditionalTrait

Class BaseBuilder

Provides the core Query Builder methods. Database-specific Builders might need to override certain methods to make them work.

Table of Contents

Properties

$QBGroupBy  : array<string|int, mixed>
QB GROUP BY data
$QBNoEscape  : array<int, bool|null>
Whether to protect identifiers in SELECT
$QBOrderBy  : array<string|int, mixed>|string|null
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.
$isLiteralStr  : array<int, string>
Strings that determine if a string represents a literal value or a field name
$joinTypes  : array<string|int, mixed>
Tables relation types
$pregOperators  : array<int, string>
RegExp used to get operators
$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<int, string>
QB keys list of column names.
$QBLimit  : bool|int
QB LIMIT data
$QBOffset  : bool|int
QB OFFSET data
$QBOptions  : array{updateFieldsAdditional?: array, tableIdentity?: string, updateFields?: array, constraints?: array, setQueryAsData?: string, sql?: string, alias?: string, fieldTypes?: array>}
QB Options data Holds additional options and data used to render SQL and is reset by resetWrite()
$QBSelect  : array<string|int, mixed>
QB SELECT data
$QBSet  : array<string, string>|array<int, array<int, int|string>>
QB data sets
$QBUnion  : array<int, string>
QB UNION data
$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.

Methods

__construct()  : mixed
Constructor
countAll()  : int|string
Generates a platform-specific query string that counts all records in the particular table
countAllResults()  : int|string
Generates a platform-specific query string that counts all records returned by an Query Builder query.
db()  : BaseConnection
Returns the current database connection
decrement()  : bool
Decrements a numeric column by the specified value.
delete()  : bool|string
Compiles a delete string and runs the query
deleteBatch()  : false|int|array<int, string>
Sets data and calls batchExecute to run queries
distinct()  : $this
Sets a flag which tells the query string compiler to add DISTINCT
emptyTable()  : bool|string
Compiles a delete string and runs "DELETE FROM table"
from()  : $this
Generates the FROM portion of the query
fromSubquery()  : $this
get()  : false|ResultInterface
Compiles the select statement based on the other functions called and runs the query
getBinds()  : array<string|int, mixed>
Returns an array of bind values and their named parameters for binding in the Query object later.
getCompiledDelete()  : string
Compiles a delete query string and returns the sql
getCompiledInsert()  : bool|string
Compiles an insert query and returns the sql
getCompiledQBWhere()  : array<string|int, mixed>
Compiles the set conditions and returns the sql statement
getCompiledSelect()  : string
Compiles a SELECT query string and returns the sql.
getCompiledUpdate()  : bool|string
Compiles an update query and returns the sql
getCompiledUpsert()  : string
Compiles an upsert query and returns the sql
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
Allows the where clause, limit and offset to be added directly
groupBy()  : $this
groupEnd()  : $this
Ends a query group
groupStart()  : $this
Starts a query group.
having()  : $this
Separates multiple calls with 'AND'.
havingGroupEnd()  : $this
Ends a query group for HAVING clause.
havingGroupStart()  : $this
Starts a query group for HAVING clause.
havingIn()  : $this
Generates a HAVING field IN('item', 'item') SQL query, joined with 'AND' if appropriate.
havingLike()  : $this
Generates a %LIKE% portion of the query.
havingNotIn()  : $this
Generates a HAVING field NOT IN('item', 'item') SQL query, joined with 'AND' if appropriate.
ignore()  : $this
Ignore
increment()  : bool
Increments a numeric column by the specified value.
insert()  : BaseResult|bool|Query
Compiles an insert string and runs the query
insertBatch()  : false|int|array<int, string>
Compiles batch insert strings and runs the queries
join()  : $this
Generates the JOIN portion of the query
like()  : $this
Generates a %LIKE% portion of the query.
limit()  : $this
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
Generates a NOT LIKE portion of the query.
notLike()  : $this
Generates a NOT LIKE portion of the query.
offset()  : $this
Sets the OFFSET value
onConstraint()  : $this
Sets constraints for batch upsert, update
orderBy()  : $this
orGroupStart()  : $this
Starts a query group, but ORs the group
orHaving()  : $this
Separates multiple calls with 'OR'.
orHavingGroupStart()  : $this
Starts a query group for HAVING clause, but ORs the group.
orHavingIn()  : $this
Generates a HAVING field IN('item', 'item') SQL query, joined with 'OR' if appropriate.
orHavingLike()  : $this
Generates a %LIKE% portion of the query.
orHavingNotIn()  : $this
Generates a HAVING field NOT IN('item', 'item') SQL query, joined with 'OR' if appropriate.
orLike()  : $this
Generates a %LIKE% portion of the query.
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
Generates a NOT LIKE portion of the query.
orNotLike()  : $this
Generates a NOT LIKE portion of the query.
orWhere()  : $this
OR WHERE
orWhereIn()  : $this
Generates a WHERE field IN('item', 'item') SQL query, joined with 'OR' if appropriate.
orWhereNotIn()  : $this
Generates a WHERE field NOT IN('item', 'item') SQL query, joined with 'OR' if appropriate.
replace()  : BaseResult|false|Query|string
Compiles a replace into string and runs the query
resetQuery()  : $this
Publicly-visible method to reset the QB values.
select()  : $this
Generates the SELECT portion of the query
selectAvg()  : $this
Generates a SELECT AVG(field) portion of a query
selectCount()  : $this
Generates a SELECT COUNT(field) portion of a query
selectMax()  : $this
Generates a SELECT MAX(field) portion of a query
selectMin()  : $this
Generates a SELECT MIN(field) portion of a query
selectSubquery()  : self
Adds a subquery to the selection
selectSum()  : $this
Generates a SELECT SUM(field) portion of a query
set()  : $this
Allows key/value pairs to be set for insert(), update() or replace().
setData()  : $this|null
Allows a row or multiple rows to be set for batch inserts/upserts/updates
setInsertBatch()  : $this|null
Allows key/value pairs to be set for batch inserts
setQueryAsData()  : BaseBuilder
Sets data source as a query for insertBatch()/updateBatch()/upsertBatch()/deleteBatch()
setUpdateBatch()  : $this
Allows key/value pairs to be set for batch updating
testMode()  : $this
Sets a test mode status.
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"
union()  : $this
Add UNION statement
unionAll()  : $this
Add UNION ALL statement
update()  : bool
Compiles an update string and runs the query.
updateBatch()  : false|int|array<int, string>
Sets data and calls batchExecute to run queries
updateFields()  : $this
Sets update fields for upsert, update
upsert()  : false|int|array<int, string>
Converts call to batchUpsert
upsertBatch()  : false|int|array<int, string>
Compiles batch upsert strings and runs the queries
when()  : $this
Only runs the query when $condition evaluates to true
whenNot()  : $this
Only runs the query when $condition evaluates to false
where()  : $this
Generates the WHERE portion of the query.
whereIn()  : $this
Generates a WHERE field IN('item', 'item') SQL query, joined with 'AND' if appropriate.
whereNotIn()  : $this
Generates a WHERE field NOT IN('item', 'item') SQL query, joined with 'AND' if appropriate.
_delete()  : string
Generates a platform-specific delete string from the supplied data
_deleteBatch()  : string
Generates a platform-specific batch update string from the supplied data
_fromTables()  : string
Groups tables in FROM clauses if needed, so there is no confusion about operator precedence.
_insert()  : string
Generates a platform-specific insert string from the supplied data
_insertBatch()  : string
Generates a platform-specific insert string from the supplied data.
_like()  : $this
_like_statement()  : string
Platform independent LIKE statement builder.
_limit()  : string
Generates a platform-specific LIMIT clause.
_replace()  : string
Generates a platform-specific replace string from the supplied data
_truncate()  : string
Generates a platform-specific truncate string from the supplied data
_update()  : string
Generates a platform-specific update string from the supplied data
_updateBatch()  : string
Generates a platform-specific batch update string from the supplied data
_upsertBatch()  : string
Generates a platform-specific upsertBatch string from the supplied data
_whereIn()  : $this
addUnionStatement()  : $this
batchExecute()  : false|int|array<int, string>
Compiles batch insert/update/upsert strings and runs the queries
batchObjectToArray()  : array<string|int, mixed>
Takes an object as input and converts the class variables to array key/vals
buildSubquery()  : string
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
Escapes identifiers in GROUP BY statements at execution time.
compileIgnore()  : string
Checks if the ignore option is supported by the Database Driver for the specific statement.
compileOrderBy()  : string
Escapes identifiers in ORDER BY statements at execution time.
compileSelect()  : string
Compile the SELECT statement
compileWhereHaving()  : string
Escapes identifiers in WHERE and HAVING statements at execution time.
createAliasFromTable()  : string
Determines the alias name based on the table
fieldsFromQuery()  : array<string|int, mixed>
Gets column names from a select query
formatValues()  : array<string|int, mixed>
Converts value array of array to array of strings
getOperator()  : array<string|int, mixed>|false|string
Returns the SQL string operator
groupEndPrepare()  : $this
Prepate a query group end.
groupGetType()  : string
groupStartPrepare()  : $this
Prepate a query group start.
hasOperator()  : bool
Tests whether the string has an SQL operator
isLiteral()  : bool
Determines if a string represents a literal value or a field name
isSubquery()  : bool
maxMinAvgSum()  : $this
SELECT [MAX|MIN|AVG|SUM|COUNT]()
objectToArray()  : array<string|int, mixed>
Takes an object as input and converts the class variables to array key/vals
resetRun()  : mixed
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
Used to track SQL statements written with aliased tables.
unionInjection()  : string
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.
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 updated.
whereHaving()  : $this
getOperatorFromWhereKey()  : false|array<int, string>
Returns the SQL string operator from where key
setAlias()  : BaseBuilder
Set table alias for dataset pseudo table.

Properties

$QBGroupBy

QB GROUP BY data

public array<string|int, mixed> $QBGroupBy = []

$QBNoEscape

Whether to protect identifiers in SELECT

public array<int, bool|null> $QBNoEscape = []

true=protect, false=not protect

$QBOrderBy

QB ORDER BY data

public array<string|int, mixed>|string|null $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
used-by

CI_DB_driver::count_all()

used-by

BaseBuilder::count_all_results()

$isLiteralStr

Strings that determine if a string represents a literal value or a field name

protected array<int, string> $isLiteralStr = []

$joinTypes

Tables relation types

protected array<string|int, mixed> $joinTypes = ['LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER']

$pregOperators

RegExp used to get operators

protected array<int, string> $pregOperators = []

$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 list of column names.

protected array<int, string> $QBKeys = []

$QBLimit

QB LIMIT data

protected bool|int $QBLimit = false

$QBOffset

QB OFFSET data

protected bool|int $QBOffset = false

$QBOptions

QB Options data Holds additional options and data used to render SQL and is reset by resetWrite()

protected array{updateFieldsAdditional?: array, tableIdentity?: string, updateFields?: array, constraints?: array, setQueryAsData?: string, sql?: string, alias?: string, fieldTypes?: array>} $QBOptions

fieldTypes: [ProtectedTableName => [FieldName => Type]]

$QBSelect

QB SELECT data

protected array<string|int, mixed> $QBSelect = []

$QBSet

QB data sets

protected array<string, string>|array<int, array<int, int|string>> $QBSet = []

$QBUnion

QB UNION data

protected array<int, string> $QBUnion = []

$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 = []

$tableName

Name of the primary table for this instance.

protected string $tableName

Tracked separately because $QBFrom gets escaped and prefixed.

When $tableName to the constructor has multiple tables, the value is empty string.

$testMode

Builder testing mode status.

protected bool $testMode = false

Methods

__construct()

Constructor

public __construct(array<string|int, mixed>|string $tableName, ConnectionInterface $db[, array<string|int, mixed>|null $options = null ]) : mixed
Parameters
$tableName : array<string|int, mixed>|string

tablename or tablenames with or without aliases

Examples of $tableName: mytable, jobs j, jobs j, users u, ['jobs j','users u']

$db : ConnectionInterface
$options : array<string|int, mixed>|null = null
Tags
throws
DatabaseException

countAll()

Generates a platform-specific query string that counts all records in the particular table

public countAll([bool $reset = true ]) : int|string
Parameters
$reset : bool = true
Return values
int|string

countAllResults()

Generates a platform-specific query string that counts all records returned by an Query Builder query.

public countAllResults([bool $reset = true ]) : int|string
Parameters
$reset : bool = true
Return values
int|string

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

Compiles a delete string and runs the query

public delete([array<string|int, mixed>|RawSql|string $where = '' ][, int|null $limit = null ][, bool $resetData = true ]) : bool|string
Parameters
$where : array<string|int, mixed>|RawSql|string = ''
$limit : int|null = null
$resetData : bool = true
Tags
throws
DatabaseException
Return values
bool|string

Returns a SQL string if in test mode.

deleteBatch()

Sets data and calls batchExecute to run queries

public deleteBatch([array<string|int, mixed>|object|null $set = null ][, array<string|int, mixed>|RawSql|null $constraints = null ][, int $batchSize = 100 ]) : false|int|array<int, string>
Parameters
$set : array<string|int, mixed>|object|null = null

a dataset

$constraints : array<string|int, mixed>|RawSql|null = null
$batchSize : int = 100
Return values
false|int|array<int, string>

Number of rows affected or FALSE on failure, SQL array when testMode

distinct()

Sets a flag which tells the query string compiler to add DISTINCT

public distinct([bool $val = true ]) : $this
Parameters
$val : bool = true
Return values
$this

emptyTable()

Compiles a delete string and runs "DELETE FROM table"

public emptyTable() : bool|string
Return values
bool|string

TRUE on success, FALSE on failure, string on testMode

from()

Generates the FROM portion of the query

public from(array<string|int, mixed>|string $from[, bool $overwrite = false ]) : $this
Parameters
$from : array<string|int, mixed>|string
$overwrite : bool = false
Return values
$this

fromSubquery()

public fromSubquery(BaseBuilder $from, string $alias) : $this
Parameters
$from : BaseBuilder

Expected subquery

$alias : string

Subquery alias

Return values
$this

get()

Compiles the select statement based on the other functions called and runs the query

public get([int|null $limit = null ][, int $offset = 0 ][, bool $reset = true ]) : false|ResultInterface
Parameters
$limit : int|null = null
$offset : int = 0
$reset : bool = true
Return values
false|ResultInterface

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

Compiles a delete query string and returns the sql

public getCompiledDelete([bool $reset = true ]) : string
Parameters
$reset : bool = true
Return values
string

getCompiledInsert()

Compiles an insert query and returns the sql

public getCompiledInsert([bool $reset = true ]) : bool|string
Parameters
$reset : bool = true
Tags
throws
DatabaseException
Return values
bool|string

getCompiledQBWhere()

Compiles the set conditions and returns the sql statement

public getCompiledQBWhere() : array<string|int, mixed>
Return values
array<string|int, mixed>

getCompiledSelect()

Compiles a SELECT query string and returns the sql.

public getCompiledSelect([bool $reset = true ]) : string
Parameters
$reset : bool = true
Return values
string

getCompiledUpdate()

Compiles an update query and returns the sql

public getCompiledUpdate([bool $reset = true ]) : bool|string
Parameters
$reset : bool = true
Return values
bool|string

getCompiledUpsert()

Compiles an upsert query and returns the sql

public getCompiledUpsert() : string
Tags
throws
DatabaseException
Return values
string

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

Allows the where clause, limit and offset to be added directly

public getWhere([array<string|int, mixed>|string $where = null ][, int|null $limit = null ][, int|null $offset = 0 ][, bool $reset = true ]) : ResultInterface
Parameters
$where : array<string|int, mixed>|string = null
$limit : int|null = null
$offset : int|null = 0
$reset : bool = true
Return values
ResultInterface

groupBy()

public groupBy(array<string|int, mixed>|string $by[, bool|null $escape = null ]) : $this
Parameters
$by : array<string|int, mixed>|string
$escape : bool|null = 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()

Separates multiple calls with 'AND'.

public having(array<string|int, mixed>|RawSql|string $key[, mixed $value = null ][, bool|null $escape = null ]) : $this
Parameters
$key : array<string|int, mixed>|RawSql|string
$value : mixed = null
$escape : bool|null = 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()

Generates a HAVING field IN('item', 'item') SQL query, joined with 'AND' if appropriate.

public havingIn([string|null $key = null ][, array<string|int, mixed>|BaseBuilder|Closure|string $values = null ][, bool|null $escape = null ]) : $this
Parameters
$key : string|null = null
$values : array<string|int, mixed>|BaseBuilder|Closure|string = null

The values searched on, or anonymous function with subquery

$escape : bool|null = null
Return values
$this

havingLike()

Generates a %LIKE% portion of the query.

public havingLike(array<string|int, mixed>|RawSql|string $field[, string $match = '' ][, string $side = 'both' ][, bool|null $escape = null ][, bool $insensitiveSearch = false ]) : $this

Separates multiple calls with 'AND'.

Parameters
$field : array<string|int, mixed>|RawSql|string
$match : string = ''
$side : string = 'both'
$escape : bool|null = null
$insensitiveSearch : bool = false
Return values
$this

havingNotIn()

Generates a HAVING field NOT IN('item', 'item') SQL query, joined with 'AND' if appropriate.

public havingNotIn([string|null $key = null ][, array<string|int, mixed>|BaseBuilder|Closure|string $values = null ][, bool|null $escape = null ]) : $this
Parameters
$key : string|null = null
$values : array<string|int, mixed>|BaseBuilder|Closure|string = null

The values searched on, or anonymous function with subquery

$escape : bool|null = 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()

Compiles an insert string and runs the query

public insert([array<string|int, mixed>|object|null $set = null ][, bool|null $escape = null ]) : BaseResult|bool|Query
Parameters
$set : array<string|int, mixed>|object|null = null
$escape : bool|null = null
Tags
throws
DatabaseException
Return values
BaseResult|bool|Query

insertBatch()

Compiles batch insert strings and runs the queries

public insertBatch([array<string|int, mixed>|object|null $set = null ][, bool|null $escape = null ][, int $batchSize = 100 ]) : false|int|array<int, string>
Parameters
$set : array<string|int, mixed>|object|null = null

a dataset

$escape : bool|null = null
$batchSize : int = 100
Return values
false|int|array<int, string>

Number of rows inserted or FALSE on failure, SQL array when testMode

join()

Generates the JOIN portion of the query

public join(string $table, RawSql|string $cond[, string $type = '' ][, bool|null $escape = null ]) : $this
Parameters
$table : string
$cond : RawSql|string
$type : string = ''
$escape : bool|null = null
Return values
$this

like()

Generates a %LIKE% portion of the query.

public like(array<string|int, mixed>|RawSql|string $field[, string $match = '' ][, string $side = 'both' ][, bool|null $escape = null ][, bool $insensitiveSearch = false ]) : $this

Separates multiple calls with 'AND'.

Parameters
$field : array<string|int, mixed>|RawSql|string
$match : string = ''
$side : string = 'both'
$escape : bool|null = null
$insensitiveSearch : bool = false
Return values
$this

limit()

public limit([int|null $value = null ][, int|null $offset = 0 ]) : $this
Parameters
$value : int|null = null
$offset : int|null = 0
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()

Generates a NOT LIKE portion of the query.

public notHavingLike(array<string|int, mixed>|RawSql|string $field[, string $match = '' ][, string $side = 'both' ][, bool|null $escape = null ][, bool $insensitiveSearch = false ]) : $this

Separates multiple calls with 'AND'.

Parameters
$field : array<string|int, mixed>|RawSql|string
$match : string = ''
$side : string = 'both'
$escape : bool|null = null
$insensitiveSearch : bool = false
Return values
$this

notLike()

Generates a NOT LIKE portion of the query.

public notLike(array<string|int, mixed>|RawSql|string $field[, string $match = '' ][, string $side = 'both' ][, bool|null $escape = null ][, bool $insensitiveSearch = false ]) : $this

Separates multiple calls with 'AND'.

Parameters
$field : array<string|int, mixed>|RawSql|string
$match : string = ''
$side : string = 'both'
$escape : bool|null = null
$insensitiveSearch : bool = false
Return values
$this

offset()

Sets the OFFSET value

public offset(int $offset) : $this
Parameters
$offset : int
Return values
$this

onConstraint()

Sets constraints for batch upsert, update

public onConstraint(array<string|int, mixed>|RawSql|string $set) : $this
Parameters
$set : array<string|int, mixed>|RawSql|string

a string of columns, key value pairs, or RawSql

Return values
$this

orderBy()

public orderBy(string $orderBy[, string $direction = '' ][, bool|null $escape = null ]) : $this
Parameters
$orderBy : string
$direction : string = ''

ASC, DESC or RANDOM

$escape : bool|null = null
Return values
$this

orGroupStart()

Starts a query group, but ORs the group

public orGroupStart() : $this
Return values
$this

orHaving()

Separates multiple calls with 'OR'.

public orHaving(array<string|int, mixed>|RawSql|string $key[, mixed $value = null ][, bool|null $escape = null ]) : $this
Parameters
$key : array<string|int, mixed>|RawSql|string
$value : mixed = null
$escape : bool|null = null
Return values
$this

orHavingGroupStart()

Starts a query group for HAVING clause, but ORs the group.

public orHavingGroupStart() : $this
Return values
$this

orHavingIn()

Generates a HAVING field IN('item', 'item') SQL query, joined with 'OR' if appropriate.

public orHavingIn([string|null $key = null ][, array<string|int, mixed>|BaseBuilder|Closure|string $values = null ][, bool|null $escape = null ]) : $this
Parameters
$key : string|null = null
$values : array<string|int, mixed>|BaseBuilder|Closure|string = null

The values searched on, or anonymous function with subquery

$escape : bool|null = null
Return values
$this

orHavingLike()

Generates a %LIKE% portion of the query.

public orHavingLike(array<string|int, mixed>|RawSql|string $field[, string $match = '' ][, string $side = 'both' ][, bool|null $escape = null ][, bool $insensitiveSearch = false ]) : $this

Separates multiple calls with 'OR'.

Parameters
$field : array<string|int, mixed>|RawSql|string
$match : string = ''
$side : string = 'both'
$escape : bool|null = null
$insensitiveSearch : bool = false
Return values
$this

orHavingNotIn()

Generates a HAVING field NOT IN('item', 'item') SQL query, joined with 'OR' if appropriate.

public orHavingNotIn([string|null $key = null ][, array<string|int, mixed>|BaseBuilder|Closure|string $values = null ][, bool|null $escape = null ]) : $this
Parameters
$key : string|null = null
$values : array<string|int, mixed>|BaseBuilder|Closure|string = null

The values searched on, or anonymous function with subquery

$escape : bool|null = null
Return values
$this

orLike()

Generates a %LIKE% portion of the query.

public orLike(array<string|int, mixed>|RawSql|string $field[, string $match = '' ][, string $side = 'both' ][, bool|null $escape = null ][, bool $insensitiveSearch = false ]) : $this

Separates multiple calls with 'OR'.

Parameters
$field : array<string|int, mixed>|RawSql|string
$match : string = ''
$side : string = 'both'
$escape : bool|null = null
$insensitiveSearch : bool = false
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()

Generates a NOT LIKE portion of the query.

public orNotHavingLike(array<string|int, mixed>|RawSql|string $field[, string $match = '' ][, string $side = 'both' ][, bool|null $escape = null ][, bool $insensitiveSearch = false ]) : $this

Separates multiple calls with 'OR'.

Parameters
$field : array<string|int, mixed>|RawSql|string
$match : string = ''
$side : string = 'both'
$escape : bool|null = null
$insensitiveSearch : bool = false
Return values
$this

orNotLike()

Generates a NOT LIKE portion of the query.

public orNotLike(array<string|int, mixed>|RawSql|string $field[, string $match = '' ][, string $side = 'both' ][, bool|null $escape = null ][, bool $insensitiveSearch = false ]) : $this

Separates multiple calls with 'OR'.

Parameters
$field : array<string|int, mixed>|RawSql|string
$match : string = ''
$side : string = 'both'
$escape : bool|null = null
$insensitiveSearch : bool = false
Return values
$this

orWhere()

OR WHERE

public orWhere(array<string|int, mixed>|RawSql|string $key[, mixed $value = null ][, bool|null $escape = null ]) : $this

Generates the WHERE portion of the query. Separates multiple calls with 'OR'.

Parameters
$key : array<string|int, mixed>|RawSql|string
$value : mixed = null
$escape : bool|null = null
Return values
$this

orWhereIn()

Generates a WHERE field IN('item', 'item') SQL query, joined with 'OR' if appropriate.

public orWhereIn([string|null $key = null ][, array<string|int, mixed>|BaseBuilder|Closure|string $values = null ][, bool|null $escape = null ]) : $this
Parameters
$key : string|null = null
$values : array<string|int, mixed>|BaseBuilder|Closure|string = null

The values searched on, or anonymous function with subquery

$escape : bool|null = null
Return values
$this

orWhereNotIn()

Generates a WHERE field NOT IN('item', 'item') SQL query, joined with 'OR' if appropriate.

public orWhereNotIn([string|null $key = null ][, array<string|int, mixed>|BaseBuilder|Closure|string $values = null ][, bool|null $escape = null ]) : $this
Parameters
$key : string|null = null
$values : array<string|int, mixed>|BaseBuilder|Closure|string = null

The values searched on, or anonymous function with subquery

$escape : bool|null = null
Return values
$this

resetQuery()

Publicly-visible method to reset the QB values.

public resetQuery() : $this
Return values
$this

select()

Generates the SELECT portion of the query

public select([array<int, RawSql|string>|RawSql|string $select = '*' ][, bool|null $escape = null ]) : $this
Parameters
$select : array<int, RawSql|string>|RawSql|string = '*'
$escape : bool|null = null

Whether to protect identifiers

Return values
$this

selectAvg()

Generates a SELECT AVG(field) portion of a query

public selectAvg([string $select = '' ][, string $alias = '' ]) : $this
Parameters
$select : string = ''
$alias : string = ''
Return values
$this

selectCount()

Generates a SELECT COUNT(field) portion of a query

public selectCount([string $select = '' ][, string $alias = '' ]) : $this
Parameters
$select : string = ''
$alias : string = ''
Return values
$this

selectMax()

Generates a SELECT MAX(field) portion of a query

public selectMax([string $select = '' ][, string $alias = '' ]) : $this
Parameters
$select : string = ''
$alias : string = ''
Return values
$this

selectMin()

Generates a SELECT MIN(field) portion of a query

public selectMin([string $select = '' ][, string $alias = '' ]) : $this
Parameters
$select : string = ''
$alias : string = ''
Return values
$this

selectSubquery()

Adds a subquery to the selection

public selectSubquery(BaseBuilder $subquery, string $as) : self
Parameters
$subquery : BaseBuilder
$as : string
Return values
self

selectSum()

Generates a SELECT SUM(field) portion of a query

public selectSum([string $select = '' ][, string $alias = '' ]) : $this
Parameters
$select : string = ''
$alias : string = ''
Return values
$this

set()

Allows key/value pairs to be set for insert(), update() or replace().

public set(array<string|int, mixed>|object|string $key[, mixed $value = '' ][, bool|null $escape = null ]) : $this
Parameters
$key : array<string|int, mixed>|object|string

Field name, or an array of field/value pairs, or an object

$value : mixed = ''

Field value, if $key is a single field

$escape : bool|null = null

Whether to escape values

Return values
$this

setData()

Allows a row or multiple rows to be set for batch inserts/upserts/updates

public setData(array<string|int, mixed>|object $set[, bool|null $escape = null ][, string $alias = '' ]) : $this|null
Parameters
$set : array<string|int, mixed>|object
$escape : bool|null = null
$alias : string = ''

alias for sql table

Return values
$this|null

setInsertBatch()

Allows key/value pairs to be set for batch inserts

public setInsertBatch(mixed $key[, string $value = '' ][, bool|null $escape = null ]) : $this|null
Parameters
$key : mixed
$value : string = ''
$escape : bool|null = null
Return values
$this|null

setQueryAsData()

Sets data source as a query for insertBatch()/updateBatch()/upsertBatch()/deleteBatch()

public setQueryAsData(BaseBuilder|RawSql $query[, string|null $alias = null ][, array<string|int, mixed>|string|null $columns = null ]) : BaseBuilder
Parameters
$query : BaseBuilder|RawSql
$alias : string|null = null
$columns : array<string|int, mixed>|string|null = null

an array or comma delimited string of columns

Return values
BaseBuilder

setUpdateBatch()

Allows key/value pairs to be set for batch updating

public setUpdateBatch(array<string|int, mixed>|object $key[, string $index = '' ][, bool|null $escape = null ]) : $this
Parameters
$key : array<string|int, mixed>|object
$index : string = ''
$escape : bool|null = null
Tags
throws
DatabaseException
Return values
$this

testMode()

Sets a test mode status.

public testMode([bool $mode = true ]) : $this
Parameters
$mode : bool = true
Return values
$this

truncate()

Compiles a truncate string and runs the query If the database does not support the truncate() command This function maps to "DELETE FROM table"

public truncate() : bool|string
Return values
bool|string

TRUE on success, FALSE on failure, string on testMode

update()

Compiles an update string and runs the query.

public update([array<string|int, mixed>|object|null $set = null ][, array<string|int, mixed>|RawSql|string|null $where = null ][, int|null $limit = null ]) : bool
Parameters
$set : array<string|int, mixed>|object|null = null
$where : array<string|int, mixed>|RawSql|string|null = null
$limit : int|null = null
Tags
throws
DatabaseException
Return values
bool

updateBatch()

Sets data and calls batchExecute to run queries

public updateBatch([array<string|int, mixed>|object|null $set = null ][, array<string|int, mixed>|RawSql|string|null $constraints = null ][, int $batchSize = 100 ]) : false|int|array<int, string>
Parameters
$set : array<string|int, mixed>|object|null = null

a dataset

$constraints : array<string|int, mixed>|RawSql|string|null = null
$batchSize : int = 100
Return values
false|int|array<int, string>

Number of rows affected or FALSE on failure, SQL array when testMode

updateFields()

Sets update fields for upsert, update

public updateFields(array<int, RawSql>|array<int, string>|string $set[, bool $addToDefault = false ][, array<string|int, mixed>|null $ignore = null ]) : $this
Parameters
$set : array<int, RawSql>|array<int, string>|string
$addToDefault : bool = false

adds update fields to the default ones

$ignore : array<string|int, mixed>|null = null

ignores items in set

Return values
$this

upsert()

Converts call to batchUpsert

public upsert([array<string|int, mixed>|object|null $set = null ][, bool|null $escape = null ]) : false|int|array<int, string>
Parameters
$set : array<string|int, mixed>|object|null = null
$escape : bool|null = null
Tags
throws
DatabaseException
Return values
false|int|array<int, string>

Number of affected rows or FALSE on failure, SQL array when testMode

upsertBatch()

Compiles batch upsert strings and runs the queries

public upsertBatch([array<string|int, mixed>|object|null $set = null ][, bool|null $escape = null ][, int $batchSize = 100 ]) : false|int|array<int, string>
Parameters
$set : array<string|int, mixed>|object|null = null

a dataset

$escape : bool|null = null
$batchSize : int = 100
Tags
throws
DatabaseException
Return values
false|int|array<int, string>

Number of affected rows or FALSE on failure, SQL array when testMode

when()

Only runs the query when $condition evaluates to true

public when(array<string|int, mixed>|bool|float|int|object|resource|string|null $condition, callable $callback[, callable|null $defaultCallback = null ]) : $this
Parameters
$condition : array<string|int, mixed>|bool|float|int|object|resource|string|null
$callback : callable
$defaultCallback : callable|null = null
Tags
template

TWhen of mixed

phpstan-param

TWhen $condition

phpstan-param

callable(self, TWhen): mixed $callback

phpstan-param

(callable(self): mixed)|null $defaultCallback

Return values
$this

whenNot()

Only runs the query when $condition evaluates to false

public whenNot(array<string|int, mixed>|bool|float|int|object|resource|string|null $condition, callable $callback[, callable|null $defaultCallback = null ]) : $this
Parameters
$condition : array<string|int, mixed>|bool|float|int|object|resource|string|null
$callback : callable
$defaultCallback : callable|null = null
Tags
template

TWhenNot of mixed

phpstan-param

TWhenNot $condition

phpstan-param

callable(self, TWhenNot): mixed $callback

phpstan-param

(callable(self): mixed)|null $defaultCallback

Return values
$this

where()

Generates the WHERE portion of the query.

public where(array<string|int, mixed>|RawSql|string $key[, mixed $value = null ][, bool|null $escape = null ]) : $this

Separates multiple calls with 'AND'.

Parameters
$key : array<string|int, mixed>|RawSql|string
$value : mixed = null
$escape : bool|null = null
Return values
$this

whereIn()

Generates a WHERE field IN('item', 'item') SQL query, joined with 'AND' if appropriate.

public whereIn([string|null $key = null ][, array<string|int, mixed>|BaseBuilder|Closure|string $values = null ][, bool|null $escape = null ]) : $this
Parameters
$key : string|null = null
$values : array<string|int, mixed>|BaseBuilder|Closure|string = null

The values searched on, or anonymous function with subquery

$escape : bool|null = null
Return values
$this

whereNotIn()

Generates a WHERE field NOT IN('item', 'item') SQL query, joined with 'AND' if appropriate.

public whereNotIn([string|null $key = null ][, array<string|int, mixed>|BaseBuilder|Closure|string $values = null ][, bool|null $escape = null ]) : $this
Parameters
$key : string|null = null
$values : array<string|int, mixed>|BaseBuilder|Closure|string = null

The values searched on, or anonymous function with subquery

$escape : bool|null = null
Return values
$this

_delete()

Generates a platform-specific delete string from the supplied data

protected _delete(string $table) : string
Parameters
$table : string

Protected table name

Return values
string

_deleteBatch()

Generates a platform-specific batch update string from the supplied data

protected _deleteBatch(string $table, array<int, string> $keys, array<int, int|string> $values) : string
Parameters
$table : string

Protected table name

$keys : array<int, string>

QBKeys

$values : array<int, int|string>

QBSet

Tags
used-by

batchExecute()

Return values
string

_fromTables()

Groups tables in FROM clauses if needed, so there is no confusion about operator precedence.

protected _fromTables() : string

Note: This is only used (and overridden) by MySQL and SQLSRV.

Return values
string

_insert()

Generates a platform-specific insert string from the supplied data

protected _insert(string $table, array<int, string> $keys, array<int, int|string> $unescapedKeys) : string
Parameters
$table : string

Protected table name

$keys : array<int, string>

Keys of QBSet

$unescapedKeys : array<int, int|string>

Values of QBSet

Return values
string

_insertBatch()

Generates a platform-specific insert string from the supplied data.

protected _insertBatch(string $table, array<int, string> $keys, array<int, array<int, int|string>> $values) : string
Parameters
$table : string

Protected table name

$keys : array<int, string>

QBKeys

$values : array<int, array<int, int|string>>

QBSet

Tags
used-by

batchExecute()

Return values
string

_like()

protected _like(array<string, string>|RawSql|string $field[, string $match = '' ][, string $type = 'AND ' ][, string $side = 'both' ][, string $not = '' ][, bool|null $escape = null ][, bool $insensitiveSearch = false ][, string $clause = 'QBWhere' ]) : $this
Parameters
$field : array<string, string>|RawSql|string
$match : string = ''
$type : string = 'AND '
$side : string = 'both'
$not : string = ''
$escape : bool|null = null
$insensitiveSearch : bool = false
$clause : string = 'QBWhere'
Tags
used-by

like()

used-by

orLike()

used-by

notLike()

used-by

orNotLike()

used-by

havingLike()

used-by

orHavingLike()

used-by

notHavingLike()

used-by

orNotHavingLike()

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

_limit()

Generates a platform-specific LIMIT clause.

protected _limit(string $sql[, bool $offsetIgnore = false ]) : string
Parameters
$sql : string
$offsetIgnore : bool = false
Return values
string

_replace()

Generates a platform-specific replace string from the supplied data

protected _replace(string $table, array<int, string> $keys, array<int, int|string> $values) : string
Parameters
$table : string

Protected table name

$keys : array<int, string>

Keys of QBSet

$values : array<int, int|string>

Values of QBSet

Return values
string

_truncate()

Generates a platform-specific truncate string from the supplied data

protected _truncate(string $table) : string

If the database does not support the truncate() command, then this method maps to 'DELETE FROM table'

Parameters
$table : string

Protected table name

Return values
string

_update()

Generates a platform-specific update string from the supplied data

protected _update(string $table, array<string, string> $values) : string
Parameters
$table : string

Protected table name

$values : array<string, string>

QBSet

Return values
string

_updateBatch()

Generates a platform-specific batch update string from the supplied data

protected _updateBatch(string $table, array<int, string> $keys, array<int, array<int, int|string>> $values) : string
Parameters
$table : string

Protected table name

$keys : array<int, string>

QBKeys

$values : array<int, array<int, int|string>>

QBSet

Tags
used-by

batchExecute()

Return values
string

_upsertBatch()

Generates a platform-specific upsertBatch string from the supplied data

protected _upsertBatch(string $table, array<int, string> $keys, array<int, array<int, int|string>> $values) : string
Parameters
$table : string

Protected table name

$keys : array<int, string>

QBKeys

$values : array<int, array<int, int|string>>

QBSet

Tags
used-by

batchExecute()

Return values
string

_whereIn()

protected _whereIn([non-empty-string|null $key = null ][, array<string|int, mixed>|BaseBuilder|Closure|null $values = null ][, bool $not = false ][, string $type = 'AND ' ][, bool|null $escape = null ][, string $clause = 'QBWhere' ]) : $this
Parameters
$key : non-empty-string|null = null
$values : array<string|int, mixed>|BaseBuilder|Closure|null = null

The values searched on, or anonymous function with subquery

$not : bool = false
$type : string = 'AND '
$escape : bool|null = null
$clause : string = 'QBWhere'
Tags
used-by

WhereIn()

used-by

orWhereIn()

used-by

whereNotIn()

used-by

orWhereNotIn()

throws
InvalidArgumentException
Return values
$this

addUnionStatement()

protected addUnionStatement(BaseBuilder|Closure $union[, bool $all = false ]) : $this
Parameters
$union : BaseBuilder|Closure
$all : bool = false
Tags
used-by

union()

used-by

unionAll()

Return values
$this

batchExecute()

Compiles batch insert/update/upsert strings and runs the queries

protected batchExecute("_deleteBatch"|"_insertBatch"|"_updateBatch"|"_upsertBatch" $renderMethod[, int $batchSize = 100 ]) : false|int|array<int, string>
Parameters
$renderMethod : "_deleteBatch"|"_insertBatch"|"_updateBatch"|"_upsertBatch"
$batchSize : int = 100
Tags
throws
DatabaseException
Return values
false|int|array<int, string>

Number of rows inserted or FALSE on failure, SQL array when testMode

batchObjectToArray()

Takes an object as input and converts the class variables to array key/vals

protected batchObjectToArray(array<string|int, mixed>|object $object) : array<string|int, mixed>
Parameters
$object : array<string|int, mixed>|object
Return values
array<string|int, mixed>

buildSubquery()

protected buildSubquery(BaseBuilder|Closure $builder[, bool $wrapped = false ][, string $alias = '' ]) : string
Parameters
$builder : BaseBuilder|Closure
$wrapped : bool = false

Wrap the subquery in brackets

$alias : string = ''

Subquery alias

Return values
string

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

Escapes identifiers in GROUP BY statements at execution time.

protected compileGroupBy() : string

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

compileIgnore()

Checks if the ignore option is supported by the Database Driver for the specific statement.

protected compileIgnore(string $statement) : string
Parameters
$statement : string
Return values
string

compileOrderBy()

Escapes identifiers in ORDER BY statements at execution time.

protected compileOrderBy() : string

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

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

Escapes identifiers in WHERE and HAVING statements at execution time.

protected compileWhereHaving(string $qbKey) : string

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

fieldsFromQuery()

Gets column names from a select query

protected fieldsFromQuery(string $sql) : array<string|int, mixed>
Parameters
$sql : string
Return values
array<string|int, mixed>

formatValues()

Converts value array of array to array of strings

protected formatValues(array<string|int, mixed> $values) : array<string|int, mixed>
Parameters
$values : array<string|int, mixed>
Return values
array<string|int, mixed>

getOperator()

Returns the SQL string operator

protected getOperator(string $str[, bool $list = false ]) : array<string|int, mixed>|false|string
Parameters
$str : string
$list : bool = false
Return values
array<string|int, mixed>|false|string

groupEndPrepare()

Prepate a query group end.

protected groupEndPrepare([string $clause = 'QBWhere' ]) : $this
Parameters
$clause : string = 'QBWhere'
Return values
$this

groupGetType()

protected groupGetType(string $type) : string
Parameters
$type : string
Tags
used-by

groupStart()

used-by

_like()

used-by

whereHaving()

used-by

_whereIn()

used-by

havingGroupStart()

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

Determines if a string represents a literal value or a field name

protected isLiteral(string $str) : bool
Parameters
$str : string
Return values
bool

isSubquery()

protected isSubquery(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

maxMinAvgSum()

SELECT [MAX|MIN|AVG|SUM|COUNT]()

protected maxMinAvgSum([string $select = '' ][, string $alias = '' ][, string $type = 'MAX' ]) : $this
Parameters
$select : string = ''
$alias : string = ''
$type : string = 'MAX'
Tags
used-by

selectMax()

used-by

selectMin()

used-by

selectAvg()

used-by

selectSum()

throws
DatabaseException
throws
DataException
Return values
$this

objectToArray()

Takes an object as input and converts the class variables to array key/vals

protected objectToArray(array<string|int, mixed>|object $object) : array<string|int, mixed>
Parameters
$object : array<string|int, mixed>|object
Return values
array<string|int, mixed>

resetRun()

Resets the query builder values. Called by the get() function

protected resetRun(array<string|int, mixed> $qbResetItems) : mixed
Parameters
$qbResetItems : array<string|int, mixed>

An array of fields to reset

resetSelect()

Resets the query builder values. Called by the get() function

protected resetSelect() : mixed

resetWrite()

Resets the query builder "write" values.

protected resetWrite() : mixed

Called by the insert() update() insertBatch() updateBatch() and delete() functions

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

Used to track SQL statements written with aliased tables.

protected trackAliases(array<string|int, mixed>|string $table) : string|void
Parameters
$table : array<string|int, mixed>|string

The table to inspect

Return values
string|void

unionInjection()

protected unionInjection(string $sql) : string
Parameters
$sql : string
Return values
string

validateInsert()

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.

protected validateInsert() : bool
Tags
throws
DatabaseException
Return values
bool

validateUpdate()

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 updated.

protected validateUpdate() : bool
Tags
throws
DatabaseException
Return values
bool

whereHaving()

protected whereHaving(string $qbKey, array<string|int, mixed>|RawSql|string $key[, mixed $value = null ][, string $type = 'AND ' ][, bool|null $escape = null ]) : $this
Parameters
$qbKey : string
$key : array<string|int, mixed>|RawSql|string
$value : mixed = null
$type : string = 'AND '
$escape : bool|null = null
Tags
used-by

where()

used-by

orWhere()

used-by

having()

used-by

orHaving()

Return values
$this

getOperatorFromWhereKey()

Returns the SQL string operator from where key

private getOperatorFromWhereKey(string $whereKey) : false|array<int, string>
Parameters
$whereKey : string
Return values
false|array<int, string>

        
On this page

Search results