QueryBuilder
extends QueryBuilderBase
in package
implements
QueryBuilderInterface
Convenience class for creating sql queries
Interfaces, Classes, Traits and Enums
- QueryBuilderInterface
- Interface defining the Query Builder class
Table of Contents
- $connName : string
- Convenience property for connection management
- $queries : array<string|int, mixed>
- List of queries executed
- __call() : mixed
- Calls a function further down the inheritance chain.
- __construct() : mixed
- __destruct() : mixed
- affectedRows() : void
- beginTransaction() : void
- commit() : void
- 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
- errorCode() : void
- errorInfo() : void
- exec() : void
- explain() : self
- Tell the database to give you the query plan instead of result set
- 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
- getAttribute() : void
- getColumns() : void
- 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
- getDbs() : void
- getFks() : void
- getIndexes() : void
- getLastQuery() : void
- getSchemas() : void
- getSequences() : void
- getSystemTables() : void
- getTables() : void
- getTypes() : void
- getUtil() : void
- getVersion() : void
- getViews() : void
- 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
- inTransaction() : void
- join() : self
- Creates a join phrase in a compiled query
- lastInsertId() : void
- 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
- numRows() : void
- 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
- prepare() : void
- prepareExecute() : void
- prepareQuery() : void
- query() : void
- quote() : void
- resetQuery() : void
- Clear out the class variables, so the next query can be run
- returning() : $this
- Add a 'returning' clause to an insert,update, or delete query
- rollback() : void
- 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
- setAttribute() : void
- setTablePrefix() : void
- table() : self
- Specify the database table to select from
- truncate() : void
- 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
Properties
$connName
Convenience property for connection management
public
string
$connName
= ''
$queries
List of queries executed
public
array<string|int, mixed>
$queries
= ['total_time' => 0]
Methods
__call()
Calls a function further down the inheritance chain.
public
__call(string $name, array<string|int, mixed> $params) : mixed
'Implements' methods on the driver object
Parameters
- $name : string
- $params : array<string|int, mixed>
Tags
Return values
mixed —__construct()
public
__construct(DriverInterface|null $driver, QueryParser $parser) : mixed
Parameters
- $driver : DriverInterface|null
- $parser : QueryParser
Return values
mixed —__destruct()
public
__destruct() : mixed
Return values
mixed —affectedRows()
public
affectedRows() : void
: int
Return values
void —beginTransaction()
public
beginTransaction() : void
: bool
Return values
void —commit()
public
commit() : void
: bool
Return values
void —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 —errorCode()
public
errorCode() : void
: string
Return values
void —errorInfo()
public
errorInfo() : void
: array
Return values
void —exec()
public
exec(string $statement) : void
: int
Parameters
- $statement : string
Return values
void —explain()
Tell the database to give you the query plan instead of result set
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 —getAttribute()
public
getAttribute(int $attribute) : void
Parameters
- $attribute : int
Return values
void —getColumns()
public
getColumns(string $table) : void
: array | null
Parameters
- $table : string
Return values
void —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 —getDbs()
public
getDbs() : void
: array | null
Return values
void —getFks()
public
getFks(string $table) : void
: array | null
Parameters
- $table : string
Return values
void —getIndexes()
public
getIndexes(string $table) : void
: array | null
Parameters
- $table : string
Return values
void —getLastQuery()
public
getLastQuery() : void
: string
Return values
void —getSchemas()
public
getSchemas() : void
: array | null
Return values
void —getSequences()
public
getSequences() : void
: array | null
Return values
void —getSystemTables()
public
getSystemTables() : void
: array | null
Return values
void —getTables()
public
getTables() : void
: array
Return values
void —getTypes()
public
getTypes() : void
: array | null
Return values
void —getUtil()
public
getUtil() : void
: \Query\Drivers\AbstractUtil
Return values
void —getVersion()
public
getVersion() : void
: string
Return values
void —getViews()
public
getViews() : void
: array | null
Return values
void —getWhere()
Convenience method for get() with a where clause
public
getWhere(string $table[, mixed $where = [] ][, int|null $limit = NULL ][, int|null $offset = NULL ]) : PDOStatement
Parameters
- $table : string
- $where : 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[, mixed $data = [] ]) : PDOStatement|null
Parameters
- $table : string
- $data : mixed = []
Return values
PDOStatement|null —inTransaction()
public
inTransaction() : void
: bool
Return values
void —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 —lastInsertId()
public
lastInsertId(string $name = NULL) : void
: string
Parameters
- $name = NULL : string
Return values
void —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 —numRows()
public
numRows() : void
: int | null
Return values
void —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(mixed $key[, mixed $values = [] ]) : self
Parameters
- $key : mixed
- $values : mixed = []
Return values
self —orWhereIn()
Where in statement prefixed with "or"
public
orWhereIn(string $field[, mixed $val = [] ]) : self
Parameters
- $field : string
- $val : mixed = []
Return values
self —orWhereNotIn()
OR WHERE NOT IN (FOO) clause
public
orWhereNotIn(string $field[, mixed $val = [] ]) : self
Parameters
- $field : string
- $val : mixed = []
Return values
self —prepare()
public
prepare(string $statement, array<string|int, mixed> $driver_options = []) : void
: PDOStatement
Parameters
- $statement : string
- $driver_options = [] : array<string|int, mixed>
Return values
void —prepareExecute()
public
prepareExecute(string $sql, array<string|int, mixed> $params) : void
: PDOStatement
Parameters
- $sql : string
- $params : array<string|int, mixed>
Return values
void —prepareQuery()
public
prepareQuery(string $sql, array<string|int, mixed> $data) : void
: PDOStatement
Parameters
- $sql : string
- $data : array<string|int, mixed>
Return values
void —query()
public
query(string $statement) : void
: PDOStatement
Parameters
- $statement : string
Return values
void —quote()
public
quote(string $string, int $parameter_type = PDO::PARAM_STR) : void
: string
Parameters
- $string : string
- $parameter_type = PDO::PARAM_STR : int
Return values
void —resetQuery()
Clear out the class variables, so the next query can be run
public
resetQuery() : void
Return values
void —returning()
Add a 'returning' clause to an insert,update, or delete query
public
returning([string $fields = '' ]) : $this
Parameters
- $fields : string = ''
Return values
$this —rollback()
public
rollback() : void
: bool
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 $val = NULL ]) : self
Parameters
- $key : mixed
- $val : mixed = NULL
Return values
self —setAttribute()
public
setAttribute(int $attribute, mixed $value) : void
: bool
Parameters
- $attribute : int
- $value : mixed
Return values
void —setTablePrefix()
public
setTablePrefix(string $prefix) : void
: void
Parameters
- $prefix : string
Return values
void —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 —truncate()
public
truncate(string $table) : void
: PDOStatement
Parameters
- $table : string
Return values
void —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 $val = [] ]) : self
Parameters
- $field : string
- $val : mixed = []
Return values
self —whereNotIn()
WHERE NOT IN (FOO) clause
public
whereNotIn(string $field[, mixed $val = [] ]) : self
Parameters
- $field : string
- $val : mixed = []