| Fully Qualified Name: | CodeIgniter\Database\BaseBuilder |
Class BaseBuilder
Provides the core Query Builder methods. Database-specific Builders might need to override certain methods to make them work.
| Name | Description | Defined By |
|---|---|---|
| __construct() | Constructor | BaseBuilder |
| countAll() | "Count All" query | BaseBuilder |
| countAllResults() | "Count All Results" query | BaseBuilder |
| decrement() | Decrements a numeric column by the specified value. | BaseBuilder |
| delete() | Delete | BaseBuilder |
| distinct() | DISTINCT | BaseBuilder |
| emptyTable() | Empty Table | BaseBuilder |
| from() | From | BaseBuilder |
| get() | Get | BaseBuilder |
| getBinds() | Returns an array of bind values and their named parameters for binding in the Query object later. | BaseBuilder |
| getCompiledDelete() | Get DELETE query string | BaseBuilder |
| getCompiledInsert() | Get INSERT query string | BaseBuilder |
| getCompiledQBWhere() | Get compiled 'where' condition string | BaseBuilder |
| getCompiledSelect() | Get SELECT query string | BaseBuilder |
| getCompiledUpdate() | Get UPDATE query string | BaseBuilder |
| getSetData() | Returns the previously set() data, alternatively resetting it if needed. | BaseBuilder |
| getWhere() | Get_Where | BaseBuilder |
| groupBy() | GROUP BY | BaseBuilder |
| groupEnd() | Ends a query group | BaseBuilder |
| groupStart() | Starts a query group. | BaseBuilder |
| having() | HAVING | BaseBuilder |
| havingGroupEnd() | Ends a query group for HAVING clause. | BaseBuilder |
| havingGroupStart() | Starts a query group for HAVING clause. | BaseBuilder |
| havingIn() | HAVING IN | BaseBuilder |
| havingLike() | LIKE with HAVING clause | BaseBuilder |
| havingNotIn() | HAVING NOT IN | BaseBuilder |
| ignore() | Ignore | BaseBuilder |
| increment() | Increments a numeric column by the specified value. | BaseBuilder |
| insert() | Insert | BaseBuilder |
| insertBatch() | Insert_Batch | BaseBuilder |
| join() | JOIN | BaseBuilder |
| like() | LIKE | BaseBuilder |
| limit() | LIMIT | BaseBuilder |
| notGroupStart() | Starts a query group, but NOTs the group | BaseBuilder |
| notHavingGroupStart() | Starts a query group for HAVING clause, but NOTs the group. | BaseBuilder |
| notHavingLike() | NOT LIKE with HAVING clause | BaseBuilder |
| notLike() | NOT LIKE | BaseBuilder |
| offset() | Sets the OFFSET value | BaseBuilder |
| orGroupStart() | Starts a query group, but ORs the group | BaseBuilder |
| orHaving() | OR HAVING | BaseBuilder |
| orHavingGroupStart() | Starts a query group for HAVING clause, but ORs the group. | BaseBuilder |
| orHavingIn() | OR HAVING IN | BaseBuilder |
| orHavingLike() | OR LIKE with HAVING clause | BaseBuilder |
| orHavingNotIn() | OR HAVING NOT IN | BaseBuilder |
| orLike() | OR LIKE | BaseBuilder |
| orNotGroupStart() | Starts a query group, but OR NOTs the group | BaseBuilder |
| orNotHavingGroupStart() | Starts a query group for HAVING clause, but OR NOTs the group. | BaseBuilder |
| orNotHavingLike() | OR NOT LIKE with HAVING clause | BaseBuilder |
| orNotLike() | OR NOT LIKE | BaseBuilder |
| orWhere() | OR WHERE | BaseBuilder |
| orWhereIn() | OR WHERE IN | BaseBuilder |
| orWhereNotIn() | OR WHERE NOT IN | BaseBuilder |
| orderBy() | ORDER BY | BaseBuilder |
| replace() | Replace | BaseBuilder |
| resetQuery() | Reset Query Builder values. | BaseBuilder |
| select() | Select | BaseBuilder |
| selectAvg() | Select Average | BaseBuilder |
| selectCount() | Select Count | BaseBuilder |
| selectMax() | Select Max | BaseBuilder |
| selectMin() | Select Min | BaseBuilder |
| selectSum() | Select Sum | BaseBuilder |
| set() | The "set" function. | BaseBuilder |
| setInsertBatch() | The "setInsertBatch" function. Allows key/value pairs to be set for batch inserts | BaseBuilder |
| setUpdateBatch() | The "setUpdateBatch" function. Allows key/value pairs to be set for batch updating | BaseBuilder |
| testMode() | Sets a test mode status. | BaseBuilder |
| truncate() | Truncate | BaseBuilder |
| update() | UPDATE | BaseBuilder |
| updateBatch() | Update_Batch | BaseBuilder |
| where() | WHERE | BaseBuilder |
| whereIn() | WHERE IN | BaseBuilder |
| whereNotIn() | WHERE NOT IN | BaseBuilder |
Constructor
| Parameter Name | Type | Description |
|---|---|---|
| $tableName | string|array | |
| $db | \CodeIgniter\Database\ConnectionInterface | |
| $options | array |
Returns:
"Count All" query
Generates a platform-specific query string that counts all records in the specified database
| Parameter Name | Type | Description |
|---|---|---|
| $reset | bool | Are |
Returns: int|string when $test = true
"Count All Results" query
Generates a platform-specific query string that counts all records returned by an Query Builder query.
| Parameter Name | Type | Description |
|---|---|---|
| $reset | bool |
Returns: int|string when $test = true
Decrements a numeric column by the specified value.
| Parameter Name | Type | Description |
|---|---|---|
| $column | string | |
| $value | int |
Returns: bool
Delete
Compiles a delete string and runs the query
| Parameter Name | Type | Description |
|---|---|---|
| $where | mixed | The |
| $limit | int | The |
| $reset_data | bool |
Returns: mixed
DISTINCT
Sets a flag which tells the query string compiler to add DISTINCT
| Parameter Name | Type | Description |
|---|---|---|
| $val | bool |
Returns: \BaseBuilder
Empty Table
Compiles a delete string and runs "DELETE FROM table"
Returns: bool TRUE on success, FALSE on failure
From
Generates the FROM portion of the query
| Parameter Name | Type | Description |
|---|---|---|
| $from | mixed | can |
| $overwrite | bool | Should |
Returns: \BaseBuilder
Get
Compiles the select statement based on the other functions called and runs the query
| Parameter Name | Type | Description |
|---|---|---|
| $limit | int | The |
| $offset | int | The |
| $reset | bool | Are |
Returns: \ResultInterface
Returns an array of bind values and their named parameters for binding in the Query object later.
Returns: array
Get DELETE query string
Compiles a delete query string and returns the sql
| Parameter Name | Type | Description |
|---|---|---|
| $reset | bool | TRUE: |
Returns: string
Get INSERT query string
Compiles an insert query and returns the sql
| Parameter Name | Type | Description |
|---|---|---|
| $reset | bool | TRUE: |
Returns: string
Get compiled 'where' condition string
Compiles the set conditions and returns the sql statement
Returns: string
Get SELECT query string
Compiles a SELECT query string and returns the sql.
| Parameter Name | Type | Description |
|---|---|---|
| $reset | bool | TRUE: |
Returns: string
Get UPDATE query string
Compiles an update query and returns the sql
| Parameter Name | Type | Description |
|---|---|---|
| $reset | bool | TRUE: |
Returns: string
Returns the previously set() data, alternatively resetting it if needed.
| Parameter Name | Type | Description |
|---|---|---|
| $clean | bool |
Returns: array
Get_Where
Allows the where clause, limit and offset to be added directly
| Parameter Name | Type | Description |
|---|---|---|
| $where | string|array | Where |
| $limit | int | Limit |
| $offset | int | Offset |
| $reset | bool | Are |
Returns: \ResultInterface
GROUP BY
| Parameter Name | Type | Description |
|---|---|---|
| $by | string|array | |
| $escape | bool |
Returns: \BaseBuilder
Ends a query group
Returns: \BaseBuilder
Starts a query group.
Returns: \BaseBuilder
HAVING
Separates multiple calls with 'AND'.
| Parameter Name | Type | Description |
|---|---|---|
| $key | string|array | |
| $value | mixed | |
| $escape | bool |
Returns: \BaseBuilder
Ends a query group for HAVING clause.
Returns: \BaseBuilder
Starts a query group for HAVING clause.
Returns: \BaseBuilder
HAVING IN
Generates a HAVING field IN('item', 'item') SQL query, joined with 'AND' if appropriate.
| Parameter Name | Type | Description |
|---|---|---|
| $key | string | The |
| $values | array|string|\Closure | The |
| $escape | bool |
Returns: \BaseBuilder
LIKE with HAVING clause
Generates a %LIKE% portion of the query. Separates multiple calls with 'AND'.
| Parameter Name | Type | Description |
|---|---|---|
| $field | mixed | |
| $match | string | |
| $side | string | |
| $escape | bool | |
| $insensitiveSearch |
Returns: \BaseBuilder
HAVING NOT IN
Generates a HAVING field NOT IN('item', 'item') SQL query, joined with 'AND' if appropriate.
| Parameter Name | Type | Description |
|---|---|---|
| $key | string | The |
| $values | array|string|\Closure | The |
| $escape | bool |
Returns: \BaseBuilder
Ignore
Set ignore Flag for next insert, update or delete query.
| Parameter Name | Type | Description |
|---|---|---|
| $ignore | bool |
Returns: \BaseBuilder
Increments a numeric column by the specified value.
| Parameter Name | Type | Description |
|---|---|---|
| $column | string | |
| $value | int |
Returns: bool
Insert
Compiles an insert string and runs the query
| Parameter Name | Type | Description |
|---|---|---|
| $set | array | An |
| $escape | bool | Whether |
Returns: \BaseResult|\Query|bool
Insert_Batch
Compiles batch insert strings and runs the queries
| Parameter Name | Type | Description |
|---|---|---|
| $set | array | An |
| $escape | bool | Whether |
| $batchSize | int | Batch |
Returns: int Number of rows inserted or FALSE on failure
JOIN
Generates the JOIN portion of the query
| Parameter Name | Type | Description |
|---|---|---|
| $table | string | |
| $cond | string | The |
| $type | string | The |
| $escape | bool | Whether |
Returns: \BaseBuilder
LIKE
Generates a %LIKE% portion of the query. Separates multiple calls with 'AND'.
| Parameter Name | Type | Description |
|---|---|---|
| $field | mixed | |
| $match | string | |
| $side | string | |
| $escape | bool | |
| $insensitiveSearch | bool | IF |
Returns: \BaseBuilder
LIMIT
| Parameter Name | Type | Description |
|---|---|---|
| $value | int | LIMIT |
| $offset | int | OFFSET |
Returns: \BaseBuilder
Starts a query group, but NOTs the group
Returns: \BaseBuilder
Starts a query group for HAVING clause, but NOTs the group.
Returns: \BaseBuilder
NOT LIKE with HAVING clause
Generates a NOT LIKE portion of the query. Separates multiple calls with 'AND'.
| Parameter Name | Type | Description |
|---|---|---|
| $field | mixed | |
| $match | string | |
| $side | string | |
| $escape | bool | |
| $insensitiveSearch |
Returns: \BaseBuilder
NOT LIKE
Generates a NOT LIKE portion of the query. Separates multiple calls with 'AND'.
| Parameter Name | Type | Description |
|---|---|---|
| $field | mixed | |
| $match | string | |
| $side | string | |
| $escape | bool | |
| $insensitiveSearch | bool | IF |
Returns: \BaseBuilder
Sets the OFFSET value
| Parameter Name | Type | Description |
|---|---|---|
| $offset | int | OFFSET |
Returns: \BaseBuilder
Starts a query group, but ORs the group
Returns: \BaseBuilder
OR HAVING
Separates multiple calls with 'OR'.
| Parameter Name | Type | Description |
|---|---|---|
| $key | string|array | |
| $value | mixed | |
| $escape | bool |
Returns: \BaseBuilder
Starts a query group for HAVING clause, but ORs the group.
Returns: \BaseBuilder
OR HAVING IN
Generates a HAVING field IN('item', 'item') SQL query, joined with 'OR' if appropriate.
| Parameter Name | Type | Description |
|---|---|---|
| $key | string | The |
| $values | array|string|\Closure | The |
| $escape | bool |
Returns: \BaseBuilder
OR LIKE with HAVING clause
Generates a %LIKE% portion of the query. Separates multiple calls with 'OR'.
| Parameter Name | Type | Description |
|---|---|---|
| $field | mixed | |
| $match | string | |
| $side | string | |
| $escape | bool | |
| $insensitiveSearch |
Returns: \BaseBuilder
OR HAVING NOT IN
Generates a HAVING field NOT IN('item', 'item') SQL query, joined with 'OR' if appropriate.
| Parameter Name | Type | Description |
|---|---|---|
| $key | string | The |
| $values | array|string|\Closure | The |
| $escape | bool |
Returns: \BaseBuilder
OR LIKE
Generates a %LIKE% portion of the query. Separates multiple calls with 'OR'.
| Parameter Name | Type | Description |
|---|---|---|
| $field | mixed | |
| $match | string | |
| $side | string | |
| $escape | bool | |
| $insensitiveSearch | bool | IF |
Returns: \BaseBuilder
Starts a query group, but OR NOTs the group
Returns: \BaseBuilder
Starts a query group for HAVING clause, but OR NOTs the group.
Returns: \BaseBuilder
OR NOT LIKE with HAVING clause
Generates a NOT LIKE portion of the query. Separates multiple calls with 'OR'.
| Parameter Name | Type | Description |
|---|---|---|
| $field | mixed | |
| $match | string | |
| $side | string | |
| $escape | bool | |
| $insensitiveSearch |
Returns: \BaseBuilder
OR NOT LIKE
Generates a NOT LIKE portion of the query. Separates multiple calls with 'OR'.
| Parameter Name | Type | Description |
|---|---|---|
| $field | mixed | |
| $match | string | |
| $side | string | |
| $escape | bool | |
| $insensitiveSearch | bool | IF |
Returns: \BaseBuilder
OR WHERE
Generates the WHERE portion of the query. Separates multiple calls with 'OR'.
| Parameter Name | Type | Description |
|---|---|---|
| $key | mixed | |
| $value | mixed | |
| $escape | bool |
Returns: \BaseBuilder
OR WHERE IN
Generates a WHERE field IN('item', 'item') SQL query, joined with 'OR' if appropriate.
| Parameter Name | Type | Description |
|---|---|---|
| $key | string | The |
| $values | array|string|\Closure | The |
| $escape | bool |
Returns: \BaseBuilder
OR WHERE NOT IN
Generates a WHERE field NOT IN('item', 'item') SQL query, joined with 'OR' if appropriate.
| Parameter Name | Type | Description |
|---|---|---|
| $key | string | The |
| $values | array|string|\Closure | The |
| $escape | bool |
Returns: \BaseBuilder
ORDER BY
| Parameter Name | Type | Description |
|---|---|---|
| $orderBy | string | |
| $direction | string | ASC, |
| $escape | bool |
Returns: \BaseBuilder
Replace
Compiles an replace into string and runs the query
| Parameter Name | Type | Description |
|---|---|---|
| $set | array | An |
Returns: \BaseResult|\Query|string|bool
Reset Query Builder values.
Publicly-visible method to reset the QB values.
Returns: \BaseBuilder
Select
Generates the SELECT portion of the query
| Parameter Name | Type | Description |
|---|---|---|
| $select | string|array | |
| $escape | bool |
Returns: \BaseBuilder
Select Average
Generates a SELECT AVG(field) portion of a query
| Parameter Name | Type | Description |
|---|---|---|
| $select | string | The |
| $alias | string | An |
Returns: \BaseBuilder
Select Count
Generates a SELECT COUNT(field) portion of a query
| Parameter Name | Type | Description |
|---|---|---|
| $select | string | The |
| $alias | string | An |
Returns: \BaseBuilder
Select Max
Generates a SELECT MAX(field) portion of a query
| Parameter Name | Type | Description |
|---|---|---|
| $select | string | The |
| $alias | string | An |
Returns: \BaseBuilder
Select Min
Generates a SELECT MIN(field) portion of a query
| Parameter Name | Type | Description |
|---|---|---|
| $select | string | The |
| $alias | string | An |
Returns: \BaseBuilder
Select Sum
Generates a SELECT SUM(field) portion of a query
| Parameter Name | Type | Description |
|---|---|---|
| $select | string | The |
| $alias | string | An |
Returns: \BaseBuilder
The "set" function.
Allows key/value pairs to be set for insert(), update() or replace().
| Parameter Name | Type | Description |
|---|---|---|
| $key | string|array|object | Field |
| $value | string | Field |
| $escape | bool | Whether |
Returns: \BaseBuilder
The "setInsertBatch" function. Allows key/value pairs to be set for batch inserts
| Parameter Name | Type | Description |
|---|---|---|
| $key | mixed | |
| $value | string | |
| $escape | bool |
Returns: \BaseBuilder|null
The "setUpdateBatch" function. Allows key/value pairs to be set for batch updating
| Parameter Name | Type | Description |
|---|---|---|
| $key | array|object | |
| $index | string | |
| $escape | bool |
Returns: \BaseBuilder|null
Sets a test mode status.
| Parameter Name | Type | Description |
|---|---|---|
| $mode | bool | Mode |
Returns: \BaseBuilder
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"
Returns: bool TRUE on success, FALSE on failure
UPDATE
Compiles an update string and runs the query.
| Parameter Name | Type | Description |
|---|---|---|
| $set | array | An |
| $where | mixed | |
| $limit | int |
Returns: bool TRUE on success, FALSE on failure
Update_Batch
Compiles an update string and runs the query
| Parameter Name | Type | Description |
|---|---|---|
| $set | array | An |
| $index | string | The |
| $batchSize | int | The |
Returns: mixed Number of rows affected, SQL string, or FALSE on failure
WHERE
Generates the WHERE portion of the query. Separates multiple calls with 'AND'.
| Parameter Name | Type | Description |
|---|---|---|
| $key | mixed | |
| $value | mixed | |
| $escape | bool |
Returns: \BaseBuilder
WHERE IN
Generates a WHERE field IN('item', 'item') SQL query, joined with 'AND' if appropriate.
| Parameter Name | Type | Description |
|---|---|---|
| $key | string | The |
| $values | array|string|\Closure | The |
| $escape | bool |
Returns: \BaseBuilder
WHERE NOT IN
Generates a WHERE field NOT IN('item', 'item') SQL query, joined with 'AND' if appropriate.
| Parameter Name | Type | Description |
|---|---|---|
| $key | string | The |
| $values | array|string|\Closure | The |
| $escape | bool |
Returns: \BaseBuilder