# Documentation

Menu

## QueryBuilder extends QueryBuilderBase
in package
implements QueryBuilderInterface

QueryBuilder.php : 28

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

QueryBuilderBase.php : 67

Convenience property for connection management

`public string $connName = ''`

#### $queries

QueryBuilderBase.php : 72

List of queries executed

`public array<string|int, mixed> $queries = ['total_time' => 0]`

### Methods

#### __call()

QueryBuilderBase.php : 113

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

throws
  BadMethodCallException

##### Return values

mixed —

#### __construct()

QueryBuilderBase.php : 94
`public __construct(DriverInterface|null $driver, QueryParser $parser) : mixed`

##### Parameters

$driver : DriverInterface|null
$parser : QueryParser

##### Return values

mixed —

#### __destruct()

QueryBuilderBase.php : 100
`public __destruct() : mixed`

##### Return values

mixed —

#### affectedRows()

QueryBuilderBase.php : 0
`public affectedRows() : void`

: int

##### Return values

void —

#### beginTransaction()

QueryBuilderBase.php : 0
`public beginTransaction() : void`

: bool

##### Return values

void —

#### commit()

QueryBuilderBase.php : 0
`public commit() : void`

: bool

##### Return values

void —

#### countAll()

QueryBuilder.php : 511

Retrieve the number of rows in the selected table

`public countAll(string $table) : int`

##### Parameters

$table : string

##### Return values

int —

#### countAllResults()

QueryBuilder.php : 523

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

QueryBuilder.php : 598

Deletes data from a table

`public delete(string $table[, mixed $where = '' ]) : PDOStatement`

##### Parameters

$table : string
$where : mixed = ''

##### Return values

PDOStatement —

#### distinct()

QueryBuilder.php : 136

Adds the 'distinct' keyword to a query

`public distinct() : self`

##### Return values

self —

#### errorCode()

QueryBuilderBase.php : 0
`public errorCode() : void`

: string

##### Return values

void —

#### errorInfo()

QueryBuilderBase.php : 0
`public errorInfo() : void`

: array

##### Return values

void —

#### exec()

QueryBuilderBase.php : 0
`public exec(string $statement) : void`

: int

##### Parameters

$statement : string

##### Return values

void —

#### explain()

QueryBuilder.php : 147

Tell the database to give you the query plan instead of result set

`public explain() : self`

##### Return values

self —

#### from()

QueryBuilder.php : 167

Specify the database table to select from

`public from(string $tableName) : self`

##### Parameters

$tableName : string

##### Return values

self —

#### get()

QueryBuilder.php : 477

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

QueryBuilderBase.php : 0
`public getAttribute(int $attribute) : void`

##### Parameters

$attribute : int

##### Return values

void —

#### getColumns()

QueryBuilderBase.php : 0
`public getColumns(string $table) : void`

: array | null

##### Parameters

$table : string

##### Return values

void —

#### getCompiledDelete()

QueryBuilder.php : 645

Returns the generated 'delete' sql query

`public getCompiledDelete([string $table = '' ][, bool $reset = TRUE ]) : string`

##### Parameters

$table : string = ''
$reset : bool = TRUE

##### Return values

string —

#### getCompiledInsert()

QueryBuilder.php : 629

Returns the generated 'insert' sql query

`public getCompiledInsert(string $table[, bool $reset = TRUE ]) : string`

##### Parameters

$table : string
$reset : bool = TRUE

##### Return values

string —

#### getCompiledSelect()

QueryBuilder.php : 615

Returns the generated 'select' sql query

`public getCompiledSelect([string $table = '' ][, bool $reset = TRUE ]) : string`

##### Parameters

$table : string = ''
$reset : bool = TRUE

##### Return values

string —

#### getCompiledUpdate()

QueryBuilder.php : 637

Returns the generated 'update' sql query

`public getCompiledUpdate([string $table = '' ][, bool $reset = TRUE ]) : string`

##### Parameters

$table : string = ''
$reset : bool = TRUE

##### Return values

string —

#### getDbs()

QueryBuilderBase.php : 0
`public getDbs() : void`

: array | null

##### Return values

void —

#### getFks()

QueryBuilderBase.php : 0
`public getFks(string $table) : void`

: array | null

##### Parameters

$table : string

##### Return values

void —

#### getIndexes()

QueryBuilderBase.php : 0
`public getIndexes(string $table) : void`

: array | null

##### Parameters

$table : string

##### Return values

void —

#### getLastQuery()

QueryBuilderBase.php : 0
`public getLastQuery() : void`

: string

##### Return values

void —

#### getSchemas()

QueryBuilderBase.php : 0
`public getSchemas() : void`

: array | null

##### Return values

void —

#### getSequences()

QueryBuilderBase.php : 0
`public getSequences() : void`

: array | null

##### Return values

void —

#### getSystemTables()

QueryBuilderBase.php : 0
`public getSystemTables() : void`

: array | null

##### Return values

void —

#### getTables()

QueryBuilderBase.php : 0
`public getTables() : void`

: array

##### Return values

void —

#### getTypes()

QueryBuilderBase.php : 0
`public getTypes() : void`

: array | null

##### Return values

void —

#### getUtil()

QueryBuilderBase.php : 0
`public getUtil() : void`

: \Query\Drivers\AbstractUtil

##### Return values

void —

#### getVersion()

QueryBuilderBase.php : 0
`public getVersion() : void`

: string

##### Return values

void —

#### getViews()

QueryBuilderBase.php : 0
`public getViews() : void`

: array | null

##### Return values

void —

#### getWhere()

QueryBuilder.php : 499

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

QueryBuilder.php : 344

Group the results by the selected field(s)

`public groupBy(mixed $field) : self`

##### Parameters

$field : mixed

##### Return values

self —

#### groupEnd()

QueryBuilder.php : 463

Ends a query group

`public groupEnd() : self`

##### Return values

self —

#### groupStart()

QueryBuilder.php : 416

Adds a paren to the current query for query grouping

`public groupStart() : self`

##### Return values

self —

#### having()

QueryBuilder.php : 224

Generates a 'Having' clause

`public having(mixed $key[, mixed $values = [] ]) : self`

##### Parameters

$key : mixed
$values : mixed = []

##### Return values

self —

#### insert()

QueryBuilder.php : 540

Creates an insert clause, and executes it

`public insert(string $table[, mixed $data = [] ]) : PDOStatement`

##### Parameters

$table : string
$data : mixed = []

##### Return values

PDOStatement —

#### insertBatch()

QueryBuilder.php : 553

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

QueryBuilderBase.php : 0
`public inTransaction() : void`

: bool

##### Return values

void —

#### join()

QueryBuilder.php : 324

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

QueryBuilderBase.php : 0
`public lastInsertId(string $name = NULL) : void`

: string

##### Parameters

$name = NULL : string

##### Return values

void —

#### like()

QueryBuilder.php : 189

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

QueryBuilder.php : 402

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

QueryBuilder.php : 429

Adds a paren to the current query for query grouping, prefixed with 'NOT'

`public notGroupStart() : self`

##### Return values

self —

#### notLike()

QueryBuilder.php : 205

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

QueryBuilderBase.php : 0
`public numRows() : void`

: int | null

##### Return values

void —

#### orderBy()

QueryBuilder.php : 367

Order the results by the selected field(s)

`public orderBy(string $field[, string $type = '' ]) : self`

##### Parameters

$field : string
$type : string = ''

##### Return values

self —

#### orGroupStart()

QueryBuilder.php : 442

Adds a paren to the current query for query grouping, prefixed with 'OR'

`public orGroupStart() : self`

##### Return values

self —

#### orHaving()

QueryBuilder.php : 232

Generates a 'Having' clause prefixed with 'OR'

`public orHaving(mixed $key[, mixed $values = [] ]) : self`

##### Parameters

$key : mixed
$values : mixed = []

##### Return values

self —

#### orLike()

QueryBuilder.php : 197

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

QueryBuilder.php : 453

Adds a paren to the current query for query grouping, prefixed with 'OR NOT'

`public orNotGroupStart() : self`

##### Return values

self —

#### orNotLike()

QueryBuilder.php : 213

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

QueryBuilder.php : 253

Where clause prefixed with "OR"

`public orWhere(mixed $key[, mixed $values = [] ]) : self`

##### Parameters

$key : mixed
$values : mixed = []

##### Return values

self —

#### orWhereIn()

QueryBuilder.php : 269

Where in statement prefixed with "or"

`public orWhereIn(string $field[, mixed $val = [] ]) : self`

##### Parameters

$field : string
$val : mixed = []

##### Return values

self —

#### orWhereNotIn()

QueryBuilder.php : 285

OR WHERE NOT IN (FOO) clause

`public orWhereNotIn(string $field[, mixed $val = [] ]) : self`

##### Parameters

$field : string
$val : mixed = []

##### Return values

self —

#### prepare()

QueryBuilderBase.php : 0
`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()

QueryBuilderBase.php : 0
`public prepareExecute(string $sql, array<string|int, mixed> $params) : void`

: PDOStatement

##### Parameters

$sql : string
$params : array<string|int, mixed>

##### Return values

void —

#### prepareQuery()

QueryBuilderBase.php : 0
`public prepareQuery(string $sql, array<string|int, mixed> $data) : void`

: PDOStatement

##### Parameters

$sql : string
$data : array<string|int, mixed>

##### Return values

void —

#### query()

QueryBuilderBase.php : 0
`public query(string $statement) : void`

: PDOStatement

##### Parameters

$statement : string

##### Return values

void —

#### quote()

QueryBuilderBase.php : 0
`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()

QueryBuilderBase.php : 126

Clear out the class variables, so the next query can be run

`public resetQuery() : void`

##### Return values

void —

#### returning()

QueryBuilder.php : 120

Add a 'returning' clause to an insert,update, or delete query

`public returning([string $fields = '' ]) : $this`

##### Parameters

$fields : string = ''

##### Return values

$this —

#### rollback()

QueryBuilderBase.php : 0
`public rollback() : void`

: bool

##### Return values

void —

#### select()

QueryBuilder.php : 36

Specifies rows to select in a query

`public select(string $fields) : self`

##### Parameters

$fields : string

##### Return values

self —

#### selectAvg()

QueryBuilder.php : 96

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

QueryBuilder.php : 74

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

QueryBuilder.php : 85

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

QueryBuilder.php : 107

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

QueryBuilder.php : 296

Sets values for inserts / updates / deletes

`public set(mixed $key[, mixed $val = NULL ]) : self`

##### Parameters

$key : mixed
$val : mixed = NULL

##### Return values

self —

#### setAttribute()

QueryBuilderBase.php : 0
`public setAttribute(int $attribute, mixed $value) : void`

: bool

##### Parameters

$attribute : int
$value : mixed

##### Return values

void —

#### setTablePrefix()

QueryBuilderBase.php : 0
`public setTablePrefix(string $prefix) : void`

: void

##### Parameters

$prefix : string

##### Return values

void —

#### table()

QueryBuilder.php : 159

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

QueryBuilderBase.php : 0
`public truncate(string $table) : void`

: PDOStatement

##### Parameters

$table : string

##### Return values

void —

#### update()

QueryBuilder.php : 566

Creates an update clause, and executes it

`public update(string $table[, mixed $data = [] ]) : PDOStatement`

##### Parameters

$table : string
$data : mixed = []

##### Return values

PDOStatement —

#### updateBatch()

QueryBuilder.php : 580

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

QueryBuilder.php : 245

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

QueryBuilder.php : 261

Where clause with 'IN' statement

`public whereIn(string $field[, mixed $val = [] ]) : self`

##### Parameters

$field : string
$val : mixed = []

##### Return values

self —

#### whereNotIn()

QueryBuilder.php : 277

WHERE NOT IN (FOO) clause

`public whereNotIn(string $field[, mixed $val = [] ]) : self`

##### Parameters

$field : string
$val : mixed = []

##### Return values

self —

## Search results