# Documentation

Menu

## QueryBuilderInterface
in

QueryBuilderInterface.php : 61

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

QueryBuilderInterface.php : 262

Retrieve the number of rows in the selected table

`public countAll(string $table) : int`

##### Parameters

$table : string

##### Return values

int —

#### countAllResults()

QueryBuilderInterface.php : 270

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

QueryBuilderInterface.php : 302

Deletes data from a table

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

##### Parameters

$table : string
$where : mixed = ''

##### Return values

PDOStatement —

#### distinct()

QueryBuilderInterface.php : 94

Adds the 'distinct' keyword to a query

`public distinct() : self`

##### Return values

self —

#### explain()

QueryBuilderInterface.php : 99

Shows the query plan for the query

`public explain() : self`

##### Return values

self —

#### from()

QueryBuilderInterface.php : 111

Specify the database table to select from

`public from(string $tableName) : self`

##### Parameters

$tableName : string

##### Return values

self —

#### get()

QueryBuilderInterface.php : 252

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

QueryBuilderInterface.php : 325

Returns the generated 'delete' sql query

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

##### Parameters

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

##### Return values

string —

#### getCompiledInsert()

QueryBuilderInterface.php : 315

Returns the generated 'insert' sql query

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

##### Parameters

$table : string
$reset : bool = TRUE

##### Return values

string —

#### getCompiledSelect()

QueryBuilderInterface.php : 310

Returns the generated 'select' sql query

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

##### Parameters

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

##### Return values

string —

#### getCompiledUpdate()

QueryBuilderInterface.php : 320

Returns the generated 'update' sql query

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

##### Parameters

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

##### Return values

string —

#### getWhere()

QueryBuilderInterface.php : 257

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

QueryBuilderInterface.php : 202

Group the results by the selected field(s)

`public groupBy(mixed $field) : self`

##### Parameters

$field : mixed

##### Return values

self —

#### groupEnd()

QueryBuilderInterface.php : 243

Ends a query group

`public groupEnd() : self`

##### Return values

self —

#### groupStart()

QueryBuilderInterface.php : 220

Adds a paren to the current query for query grouping

`public groupStart() : self`

##### Return values

self —

#### having()

QueryBuilderInterface.php : 142

Generates a 'Having' clause

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

##### Parameters

$key : mixed
$values : mixed = []

##### Return values

self —

#### insert()

QueryBuilderInterface.php : 275

Creates an insert clause, and executes it

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

##### Parameters

$table : string
$data : mixed = []

##### Return values

PDOStatement —

#### insertBatch()

QueryBuilderInterface.php : 282

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

QueryBuilderInterface.php : 197

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

QueryBuilderInterface.php : 119

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

QueryBuilderInterface.php : 212

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

QueryBuilderInterface.php : 226

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

`public notGroupStart() : self`

##### Return values

self —

#### notLike()

QueryBuilderInterface.php : 129

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

QueryBuilderInterface.php : 207

Order the results by the selected field(s)

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

##### Parameters

$field : string
$type : string = ''

##### Return values

self —

#### orGroupStart()

QueryBuilderInterface.php : 232

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

`public orGroupStart() : self`

##### Return values

self —

#### orHaving()

QueryBuilderInterface.php : 147

Generates a 'Having' clause prefixed with 'OR'

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

##### Parameters

$key : mixed
$values : mixed = []

##### Return values

self —

#### orLike()

QueryBuilderInterface.php : 124

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

QueryBuilderInterface.php : 238

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

`public orNotGroupStart() : self`

##### Return values

self —

#### orNotLike()

QueryBuilderInterface.php : 134

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

QueryBuilderInterface.php : 164

Where clause prefixed with "OR"

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

##### Parameters

$key : string
$values : mixed = []

##### Return values

self —

#### orWhereIn()

QueryBuilderInterface.php : 174

Where in statement prefixed with "or"

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

##### Parameters

$field : string
$values : mixed = []

##### Return values

self —

#### orWhereNotIn()

QueryBuilderInterface.php : 184

OR WHERE NOT IN (FOO) clause

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

##### Parameters

$field : string
$values : mixed = []

##### Return values

self —

#### resetQuery()

QueryBuilderInterface.php : 333

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

`public resetQuery() : void`

##### Return values

void —

#### select()

QueryBuilderInterface.php : 69

Specifies rows to select in a query

`public select(string $fields) : self`

##### Parameters

$fields : string

##### Return values

self —

#### selectAvg()

QueryBuilderInterface.php : 84

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

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

QueryBuilderInterface.php : 79

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

QueryBuilderInterface.php : 89

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

QueryBuilderInterface.php : 192

Sets values for inserts / updates / deletes

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

##### Parameters

$key : mixed
$values : mixed = NULL

##### Return values

self —

#### table()

QueryBuilderInterface.php : 106

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

QueryBuilderInterface.php : 287

Creates an update clause, and executes it

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

##### Parameters

$table : string
$data : mixed = []

##### Return values

PDOStatement —

#### updateBatch()

QueryBuilderInterface.php : 297

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

QueryBuilderInterface.php : 157

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

QueryBuilderInterface.php : 169

Where clause with 'IN' statement

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

##### Parameters

$field : string
$values : mixed = []

##### Return values

self —

#### whereNotIn()

QueryBuilderInterface.php : 179

WHERE NOT IN (FOO) clause

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

##### Parameters

$field : string
$values : mixed = []

##### Return values

self —

## Search results