Properties

$fields

$fields : array

List of fields.

Type

array

$keys

$keys : array

List of keys.

Type

array

$uniqueKeys

$uniqueKeys : array

List of unique keys.

Type

array

$primaryKeys

$primaryKeys : array

List of primary keys.

Type

array

$foreignKeys

$foreignKeys : array

List of foreign keys.

Type

array

$charset

$charset : string

Character set used.

Type

string

$createDatabaseStr

$createDatabaseStr : string

CREATE DATABASE statement

Type

string

$createDatabaseIfStr

$createDatabaseIfStr : string

CREATE DATABASE IF statement

Type

string

$checkDatabaseExistStr

$checkDatabaseExistStr : string

CHECK DATABASE EXIST statement

Type

string

$dropDatabaseStr

$dropDatabaseStr : string

DROP DATABASE statement

Type

string

$createTableStr

$createTableStr : string

CREATE TABLE statement

Type

string

$createTableIfStr

$createTableIfStr : string

CREATE TABLE IF statement

Type

string

$createTableKeys

$createTableKeys : boolean

CREATE TABLE keys flag

Whether table keys are created from within the CREATE TABLE statement.

Type

boolean

$dropTableIfStr

$dropTableIfStr : string

DROP TABLE IF EXISTS statement

Type

string

$renameTableStr

$renameTableStr : string

RENAME TABLE statement

Type

string

$unsigned

$unsigned : boolean|array

UNSIGNED support

Type

boolean|array

$null

$null : string

NULL value representation in CREATE/ALTER TABLE statements

Type

string

$default

$default : string

DEFAULT value representation in CREATE/ALTER TABLE statements

Type

string

Methods

createDatabase()

createDatabase(string  $dbName, boolean  $ifNotExists = false) : boolean

Create database

Parameters

string $dbName
boolean $ifNotExists

Whether to add IF NOT EXISTS condition

Throws

\CodeIgniter\Database\Exceptions\DatabaseException

Returns

boolean

dropDatabase()

dropDatabase(string  $dbName) : boolean

Drop database

Parameters

string $dbName

Throws

\CodeIgniter\Database\Exceptions\DatabaseException

Returns

boolean

addKey()

addKey(string|array  $key, boolean  $primary = false, boolean  $unique = false) : \CodeIgniter\Database\Forge

Add Key

Parameters

string|array $key
boolean $primary
boolean $unique

Returns

\CodeIgniter\Database\Forge

addPrimaryKey()

addPrimaryKey(string|array  $key) : \CodeIgniter\Database\Forge

Add Primary Key

Parameters

string|array $key

Returns

\CodeIgniter\Database\Forge

addUniqueKey()

addUniqueKey(string|array  $key) : \CodeIgniter\Database\Forge

Add Unique Key

Parameters

string|array $key

Returns

\CodeIgniter\Database\Forge

addField()

addField(array|string  $field) : \CodeIgniter\Database\Forge

Add Field

Parameters

array|string $field

Returns

\CodeIgniter\Database\Forge

addForeignKey()

addForeignKey(string  $fieldName = '', string  $tableName = '', string  $tableField = '', string  $onUpdate = '', string  $onDelete = '') : \CodeIgniter\Database\Forge

Add Foreign Key

Parameters

string $fieldName
string $tableName
string $tableField
string $onUpdate
string $onDelete

Throws

\CodeIgniter\Database\Exceptions\DatabaseException

Returns

\CodeIgniter\Database\Forge

dropForeignKey()

dropForeignKey(string  $table, string  $foreignName) : boolean|\CodeIgniter\Database\BaseResult|\CodeIgniter\Database\Query|false|mixed

Foreign Key Drop

Parameters

string $table

Table name

string $foreignName

Foreign name

Throws

\CodeIgniter\Database\Exceptions\DatabaseException

Returns

boolean|\CodeIgniter\Database\BaseResult|\CodeIgniter\Database\Query|false|mixed

createTable()

createTable(string  $table, boolean  $if_not_exists = false, array  $attributes = array()) : mixed

Create Table

Parameters

string $table

Table name

boolean $if_not_exists

Whether to add IF NOT EXISTS condition

array $attributes

Associative array of table attributes

Throws

\CodeIgniter\Database\Exceptions\DatabaseException

Returns

mixed

dropTable()

dropTable(string  $tableName, boolean  $ifExists = false, boolean  $cascade = false) : mixed

Drop Table

Parameters

string $tableName

Table name

boolean $ifExists

Whether to add an IF EXISTS condition

boolean $cascade

Whether to add an CASCADE condition

Throws

\CodeIgniter\Database\Exceptions\DatabaseException

Returns

mixed

renameTable()

renameTable(string  $table_name, string  $new_table_name) : mixed

Rename Table

Parameters

string $table_name

Old table name

string $new_table_name

New table name

Throws

\CodeIgniter\Database\Exceptions\DatabaseException

Returns

mixed

addColumn()

addColumn(string  $table, string|array  $field) : boolean

Column Add

Parameters

string $table

Table name

string|array $field

Column definition

Throws

\CodeIgniter\Database\Exceptions\DatabaseException

Returns

boolean

dropColumn()

dropColumn(string  $table, string  $column_name) : mixed

Column Drop

Parameters

string $table

Table name

string $column_name

Column name

Throws

\CodeIgniter\Database\Exceptions\DatabaseException

Returns

mixed

modifyColumn()

modifyColumn(string  $table, string|array  $field) : boolean

Column Modify

Parameters

string $table

Table name

string|array $field

Column definition

Throws

\CodeIgniter\Database\Exceptions\DatabaseException

Returns

boolean

reset()

reset() : void

Reset

Resets table creation vars

_createTable()

_createTable(string  $table, boolean  $if_not_exists, array  $attributes) : mixed

Create Table

Parameters

string $table

Table name

boolean $if_not_exists

Whether to add 'IF NOT EXISTS' condition

array $attributes

Associative array of table attributes

Returns

mixed

_createTableAttributes()

_createTableAttributes(array  $attributes) : string

CREATE TABLE attributes

Parameters

array $attributes

Associative array of table attributes

Returns

string

_dropTable()

_dropTable(string  $table, boolean  $if_exists, boolean  $cascade) : string

Drop Table

Generates a platform-specific DROP TABLE string

Parameters

string $table

Table name

boolean $if_exists

Whether to add an IF EXISTS condition

boolean $cascade

Whether to add an CASCADE condition

Returns

string

_alterTable()

_alterTable(string  $alter_type, string  $table, mixed  $field) : string|array<mixed,string>

ALTER TABLE

Parameters

string $alter_type

ALTER type

string $table

Table name

mixed $field

Column definition

Returns

string|array<mixed,string>

_processFields()

_processFields(boolean  $create_table = false) : array

Process fields

Parameters

boolean $create_table

Returns

array

_processColumn()

_processColumn(array  $field) : string

Process column

Parameters

array $field

Returns

string

_attributeType()

_attributeType(array  $attributes) : void

Field attribute TYPE

Performs a data type mapping between different databases.

Parameters

array $attributes

_attributeUnsigned()

_attributeUnsigned(array  $attributes, array  $field) : null|void

Field attribute UNSIGNED

Depending on the unsigned property value:

  • TRUE will always set $field['unsigned'] to 'UNSIGNED'
  • FALSE will always set $field['unsigned'] to ''
  • array(TYPE) will set $field['unsigned'] to 'UNSIGNED', if $attributes['TYPE'] is found in the array
  • array(TYPE => UTYPE) will change $field['type'], from TYPE to UTYPE in case of a match

Parameters

array $attributes
array $field

Returns

null|void

_attributeDefault()

_attributeDefault(array  $attributes, array  $field) : null|void

Field attribute DEFAULT

Parameters

array $attributes
array $field

Returns

null|void

_attributeUnique()

_attributeUnique(array  $attributes, array  $field) : void

Field attribute UNIQUE

Parameters

array $attributes
array $field

_attributeAutoIncrement()

_attributeAutoIncrement(array  $attributes, array  $field) : void

Field attribute AUTO_INCREMENT

Parameters

array $attributes
array $field

_processPrimaryKeys()

_processPrimaryKeys(string  $table) : string

Process primary keys

Parameters

string $table

Table name

Returns

string

_processIndexes()

_processIndexes(string  $table) : array

Process indexes

Parameters

string $table

Returns

array

_processForeignKeys()

_processForeignKeys(string  $table) : string

Process foreign keys

Parameters

string $table

Table name

Returns

string

databaseExists()

databaseExists(string  $dbName) : boolean

Determine if a database exists

Parameters

string $dbName

Throws

\CodeIgniter\Database\Exceptions\DatabaseException

Returns

boolean