QueryBuilderInterface
in
Interface defining the Query Builder class
Table of Contents
- countAll() : int
- Retrieve the number of rows in the selected table
- countAllResults() : int
- Retrieve the number of results for the generated query - used in place of the get() method
- delete() : PDOStatement
- Deletes data from a table
- distinct() : self
- Adds the 'distinct' keyword to a query
- explain() : self
- Shows the query plan for the query
- from() : self
- Specify the database table to select from
- get() : PDOStatement
- Select and retrieve all records from the current table, and/or execute current compiled query
- getCompiledDelete() : string
- Returns the generated 'delete' sql query
- getCompiledInsert() : string
- Returns the generated 'insert' sql query
- getCompiledSelect() : string
- Returns the generated 'select' sql query
- getCompiledUpdate() : string
- Returns the generated 'update' sql query
- getWhere() : PDOStatement
- Convenience method for get() with a where clause
- groupBy() : self
- Group the results by the selected field(s)
- groupEnd() : self
- Ends a query group
- groupStart() : self
- Adds a paren to the current query for query grouping
- having() : self
- Generates a 'Having' clause
- insert() : PDOStatement
- Creates an insert clause, and executes it
- insertBatch() : PDOStatement|null
- Creates and executes a batch insertion query
- join() : self
- Creates a join phrase in a compiled query
- like() : self
- Creates a Like clause in the sql statement
- limit() : self
- Set a limit on the current sql statement
- notGroupStart() : self
- Adds a paren to the current query for query grouping, prefixed with 'NOT'
- notLike() : self
- Generates a NOT LIKE clause
- orderBy() : self
- Order the results by the selected field(s)
- orGroupStart() : self
- Adds a paren to the current query for query grouping, prefixed with 'OR'
- orHaving() : self
- Generates a 'Having' clause prefixed with 'OR'
- orLike() : self
- Generates an OR Like clause
- orNotGroupStart() : self
- Adds a paren to the current query for query grouping, prefixed with 'OR NOT'
- orNotLike() : self
- Generates a OR NOT LIKE clause
- orWhere() : self
- Where clause prefixed with "OR"
- orWhereIn() : self
- Where in statement prefixed with "or"
- orWhereNotIn() : self
- OR WHERE NOT IN (FOO) clause
- resetQuery() : void
- Clear out the class variables, so the next query can be run
- select() : self
- Specifies rows to select in a query
- selectAvg() : self
- Selects the average value of a field from a query
- selectMax() : self
- Selects the maximum value of a field from a query
- selectMin() : self
- Selects the minimum value of a field from a query
- selectSum() : self
- Selects the sum of a field from a query
- set() : self
- Sets values for inserts / updates / deletes
- table() : self
- Specify the database table to select from
- update() : PDOStatement
- Creates an update clause, and executes it
- updateBatch() : int|null
- Creates a batch update, and executes it.
- where() : self
- Specify condition(s) in the where clause of a query Note: this function works with key / value, or a passed array with key / value pairs
- whereIn() : self
- Where clause with 'IN' statement
- whereNotIn() : self
- WHERE NOT IN (FOO) clause
Methods
countAll()
Retrieve the number of rows in the selected table
public
countAll(string $table) : int
Parameters
- $table : string
Return values
int —countAllResults()
Retrieve the number of results for the generated query - used in place of the get() method
public
countAllResults([string $table = '' ][, bool $reset = TRUE ]) : int
Parameters
- $table : string = ''
- $reset : bool = TRUE
-
- Whether to keep the query after counting the results
Return values
int —delete()
Deletes data from a table
public
delete(string $table[, mixed $where = '' ]) : PDOStatement
Parameters
- $table : string
- $where : mixed = ''
Return values
PDOStatement —distinct()
Adds the 'distinct' keyword to a query
public
distinct() : self
Return values
self —explain()
Shows the query plan for the query
public
explain() : self
Return values
self —from()
Specify the database table to select from
public
from(string $tableName) : self
Parameters
- $tableName : string
Return values
self —get()
Select and retrieve all records from the current table, and/or execute current compiled query
public
get([string $table = '' ][, int|null $limit = NULL ][, int|null $offset = NULL ]) : PDOStatement
Parameters
- $table : string = ''
- $limit : int|null = NULL
- $offset : int|null = NULL
Return values
PDOStatement —getCompiledDelete()
Returns the generated 'delete' sql query
public
getCompiledDelete([string $table = '' ][, bool $reset = TRUE ]) : string
Parameters
- $table : string = ''
- $reset : bool = TRUE
Return values
string —getCompiledInsert()
Returns the generated 'insert' sql query
public
getCompiledInsert(string $table[, bool $reset = TRUE ]) : string
Parameters
- $table : string
- $reset : bool = TRUE
Return values
string —getCompiledSelect()
Returns the generated 'select' sql query
public
getCompiledSelect([string $table = '' ][, bool $reset = TRUE ]) : string
Parameters
- $table : string = ''
- $reset : bool = TRUE
Return values
string —getCompiledUpdate()
Returns the generated 'update' sql query
public
getCompiledUpdate([string $table = '' ][, bool $reset = TRUE ]) : string
Parameters
- $table : string = ''
- $reset : bool = TRUE
Return values
string —getWhere()
Convenience method for get() with a where clause
public
getWhere(string $table[, array<string|int, mixed> $where = [] ][, int|null $limit = NULL ][, int|null $offset = NULL ]) : PDOStatement
Parameters
- $table : string
- $where : array<string|int, mixed> = []
- $limit : int|null = NULL
- $offset : int|null = NULL
Return values
PDOStatement —groupBy()
Group the results by the selected field(s)
public
groupBy(mixed $field) : self
Parameters
- $field : mixed
Return values
self —groupEnd()
Ends a query group
public
groupEnd() : self
Return values
self —groupStart()
Adds a paren to the current query for query grouping
public
groupStart() : self
Return values
self —having()
Generates a 'Having' clause
public
having(mixed $key[, mixed $values = [] ]) : self
Parameters
- $key : mixed
- $values : mixed = []
Return values
self —insert()
Creates an insert clause, and executes it
public
insert(string $table[, mixed $data = [] ]) : PDOStatement
Parameters
- $table : string
- $data : mixed = []
Return values
PDOStatement —insertBatch()
Creates and executes a batch insertion query
public
insertBatch(string $table[, array<string|int, mixed> $data = [] ]) : PDOStatement|null
Parameters
- $table : string
- $data : array<string|int, mixed> = []
Return values
PDOStatement|null —join()
Creates a join phrase in a compiled query
public
join(string $table, string $condition[, JoinType|string $type = JoinType::INNER ]) : self
Parameters
- $table : string
- $condition : string
- $type : JoinType|string = JoinType::INNER
Return values
self —like()
Creates a Like clause in the sql statement
public
like(string $field, mixed $values[, LikeType|string $pos = LikeType::BOTH ]) : self
Parameters
- $field : string
- $values : mixed
- $pos : LikeType|string = LikeType::BOTH
Return values
self —limit()
Set a limit on the current sql statement
public
limit(int $limit[, int|null $offset = NULL ]) : self
Parameters
- $limit : int
- $offset : int|null = NULL
Return values
self —notGroupStart()
Adds a paren to the current query for query grouping, prefixed with 'NOT'
public
notGroupStart() : self
Return values
self —notLike()
Generates a NOT LIKE clause
public
notLike(string $field, mixed $values[, LikeType|string $pos = LikeType::BOTH ]) : self
Parameters
- $field : string
- $values : mixed
- $pos : LikeType|string = LikeType::BOTH
Return values
self —orderBy()
Order the results by the selected field(s)
public
orderBy(string $field[, string $type = '' ]) : self
Parameters
- $field : string
- $type : string = ''
Return values
self —orGroupStart()
Adds a paren to the current query for query grouping, prefixed with 'OR'
public
orGroupStart() : self
Return values
self —orHaving()
Generates a 'Having' clause prefixed with 'OR'
public
orHaving(mixed $key[, mixed $values = [] ]) : self
Parameters
- $key : mixed
- $values : mixed = []
Return values
self —orLike()
Generates an OR Like clause
public
orLike(string $field, mixed $values[, LikeType|string $pos = LikeType::BOTH ]) : self
Parameters
- $field : string
- $values : mixed
- $pos : LikeType|string = LikeType::BOTH
Return values
self —orNotGroupStart()
Adds a paren to the current query for query grouping, prefixed with 'OR NOT'
public
orNotGroupStart() : self
Return values
self —orNotLike()
Generates a OR NOT LIKE clause
public
orNotLike(string $field, mixed $values[, LikeType|string $pos = LikeType::BOTH ]) : self
Parameters
- $field : string
- $values : mixed
- $pos : LikeType|string = LikeType::BOTH
Return values
self —orWhere()
Where clause prefixed with "OR"
public
orWhere(string $key[, mixed $values = [] ]) : self
Parameters
- $key : string
- $values : mixed = []
Return values
self —orWhereIn()
Where in statement prefixed with "or"
public
orWhereIn(string $field[, mixed $values = [] ]) : self
Parameters
- $field : string
- $values : mixed = []
Return values
self —orWhereNotIn()
OR WHERE NOT IN (FOO) clause
public
orWhereNotIn(string $field[, mixed $values = [] ]) : self
Parameters
- $field : string
- $values : mixed = []
Return values
self —resetQuery()
Clear out the class variables, so the next query can be run
public
resetQuery() : void
Return values
void —select()
Specifies rows to select in a query
public
select(string $fields) : self
Parameters
- $fields : string
Return values
self —selectAvg()
Selects the average value of a field from a query
public
selectAvg(string $field[, bool|string $as = FALSE ]) : self
Parameters
- $field : string
- $as : bool|string = FALSE
Return values
self —selectMax()
Selects the maximum value of a field from a query
public
selectMax(string $field[, bool|string $as = FALSE ]) : self
Parameters
- $field : string
- $as : bool|string = FALSE
Return values
self —selectMin()
Selects the minimum value of a field from a query
public
selectMin(string $field[, bool|string $as = FALSE ]) : self
Parameters
- $field : string
- $as : bool|string = FALSE
Return values
self —selectSum()
Selects the sum of a field from a query
public
selectSum(string $field[, bool|string $as = FALSE ]) : self
Parameters
- $field : string
- $as : bool|string = FALSE
Return values
self —set()
Sets values for inserts / updates / deletes
public
set(mixed $key[, mixed $values = NULL ]) : self
Parameters
- $key : mixed
- $values : mixed = NULL
Return values
self —table()
Specify the database table to select from
public
table(string $tableName) : self
Alias of from
method to better match CodeIgniter 4
Parameters
- $tableName : string
Return values
self —update()
Creates an update clause, and executes it
public
update(string $table[, mixed $data = [] ]) : PDOStatement
Parameters
- $table : string
- $data : mixed = []
Return values
PDOStatement —updateBatch()
Creates a batch update, and executes it.
public
updateBatch(string $table, array<string|int, mixed> $data, string $where) : int|null
Returns the number of affected rows
Parameters
- $table : string
-
The table to update
- $data : array<string|int, mixed>
-
an array of update values
- $where : string
-
The where key
Return values
int|null —where()
Specify condition(s) in the where clause of a query Note: this function works with key / value, or a passed array with key / value pairs
public
where(mixed $key[, mixed $values = [] ]) : self
Parameters
- $key : mixed
- $values : mixed = []
Return values
self —whereIn()
Where clause with 'IN' statement
public
whereIn(string $field[, mixed $values = [] ]) : self
Parameters
- $field : string
- $values : mixed = []
Return values
self —whereNotIn()
WHERE NOT IN (FOO) clause
public
whereNotIn(string $field[, mixed $values = [] ]) : self
Parameters
- $field : string
- $values : mixed = []