CodeIgniter v4.5 API

Forge extends Forge
in package

Forge for SQLite3

Table of Contents

Properties

$_unsigned  : array<string|int, mixed>|bool
UNSIGNED support
$charset  : string
Character set used.
$checkDatabaseExistStr  : string
CHECK DATABASE EXIST statement
$createDatabaseIfStr  : string
CREATE DATABASE IF statement
$createDatabaseStr  : false|string
CREATE DATABASE statement
$createTableIfStr  : bool|string
CREATE TABLE IF statement
$createTableKeys  : bool
CREATE TABLE keys flag
$createTableStr  : string
CREATE TABLE statement
$db  : Connection
The active database connection.
$default  : false|string
DEFAULT value representation in CREATE/ALTER TABLE statements
$dropConstraintStr  : string
DROP CONSTRAINT statement
$dropDatabaseStr  : false|string
DROP DATABASE statement
$dropIndexStr  : string
DROP INDEX statement
$dropTableIfStr  : bool|string
DROP TABLE IF EXISTS statement
$fields  : array<string, array<string, bool|string>|string>
List of fields in the form `[name => attributes]`
$fkAllowActions  : array<string|int, mixed>
Foreign Key Allowed Actions
$foreignKeys  : array<string|int, mixed>
List of foreign keys.
$keys  : array<int, array{fields?: list, keyName?: string}>
List of keys.
$primaryKeys  : array{fields?: list, keyName?: string}
Primary keys.
$renameTableStr  : false|string
RENAME TABLE statement
$uniqueKeys  : array<string|int, mixed>
List of unique keys.
$unsigned  : array<string|int, mixed>|bool
UNSIGNED support

Methods

__construct()  : mixed
Constructor.
addColumn()  : bool
addField()  : Forge
Add Field
addForeignKey()  : Forge
Add Foreign Key
addKey()  : Forge
Add Key
addPrimaryKey()  : Forge
Add Primary Key
addUniqueKey()  : Forge
Add Unique Key
createDatabase()  : bool
Create database
createTable()  : bool
dropColumn()  : bool
dropDatabase()  : bool
Drop database
dropForeignKey()  : bool
Foreign Key Drop
dropKey()  : bool
Drop Key
dropPrimaryKey()  : bool
Drop Primary Key
dropTable()  : bool
getConnection()  : ConnectionInterface
Provides access to the forge's current database connection.
modifyColumn()  : bool
processIndexes()  : bool
Executes Sql to add indexes without createTable
renameTable()  : bool
reset()  : mixed
Resets table creation vars
_alterTable()  : array<string|int, mixed>|string|null
_attributeAutoIncrement()  : mixed
Field attribute AUTO_INCREMENT
_attributeDefault()  : mixed
_attributeType()  : mixed
Field attribute TYPE
_attributeUnique()  : mixed
_attributeUnsigned()  : mixed
Depending on the unsigned property value:
_createTable()  : string
_createTableAttributes()  : string
_dropKeyAsConstraint()  : string
Constructs sql to check if key is a constraint.
_dropTable()  : bool|string
Generates a platform-specific DROP TABLE string
_processColumn()  : string
Process column
_processFields()  : array<string|int, mixed>
Returns $processedFields array from $this->fields data.
_processForeignKeys()  : array<string|int, mixed>
Generates SQL to add foreign keys
_processIndexes()  : array<string|int, mixed>
Generates SQL to add indexes
_processPrimaryKeys()  : string
Generates SQL to add primary key
dropKeyAsConstraint()  : bool
Checks if key needs to be dropped as a constraint.
databaseExists()  : bool
Determine if a database exists

Properties

$_unsigned

UNSIGNED support

protected array<string|int, mixed>|bool $_unsigned = false

$charset

Character set used.

protected string $charset = ''

$checkDatabaseExistStr

CHECK DATABASE EXIST statement

protected string $checkDatabaseExistStr

$createDatabaseIfStr

CREATE DATABASE IF statement

protected string $createDatabaseIfStr

$createDatabaseStr

CREATE DATABASE statement

protected false|string $createDatabaseStr = 'CREATE DATABASE %s'

$createTableIfStr

CREATE TABLE IF statement

This is no longer used.

protected bool|string $createTableIfStr = 'CREATE TABLE IF NOT EXISTS'

$createTableKeys

CREATE TABLE keys flag

protected bool $createTableKeys = false

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

$createTableStr

CREATE TABLE statement

protected string $createTableStr = "%s %s (%s\n)"

$default

DEFAULT value representation in CREATE/ALTER TABLE statements

protected false|string $default = ' DEFAULT '

$dropConstraintStr

DROP CONSTRAINT statement

protected string $dropConstraintStr

$dropDatabaseStr

DROP DATABASE statement

protected false|string $dropDatabaseStr = 'DROP DATABASE %s'

$dropIndexStr

DROP INDEX statement

protected string $dropIndexStr = 'DROP INDEX %s'

$dropTableIfStr

DROP TABLE IF EXISTS statement

protected bool|string $dropTableIfStr = 'DROP TABLE IF EXISTS'

$fields

List of fields in the form `[name => attributes]`

protected array<string, array<string, bool|string>|string> $fields = []

$fkAllowActions

Foreign Key Allowed Actions

protected array<string|int, mixed> $fkAllowActions = ['CASCADE', 'SET NULL', 'NO ACTION', 'RESTRICT', 'SET DEFAULT']

$foreignKeys

List of foreign keys.

protected array<string|int, mixed> $foreignKeys = []

$keys

List of keys.

protected array<int, array{fields?: list, keyName?: string}> $keys = []

$primaryKeys

Primary keys.

protected array{fields?: list, keyName?: string} $primaryKeys = []

$renameTableStr

RENAME TABLE statement

protected false|string $renameTableStr = 'ALTER TABLE %s RENAME TO %s'

$uniqueKeys

List of unique keys.

protected array<string|int, mixed> $uniqueKeys = []

$unsigned

UNSIGNED support

protected array<string|int, mixed>|bool $unsigned = true

Methods

addColumn()

public addColumn(string $table, array<string, array<string|int, mixed>|string>|string $fields) : bool
Parameters
$table : string
$fields : array<string, array<string|int, mixed>|string>|string

Field array or Field string

Tags
throws
DatabaseException
Return values
bool

addField()

Add Field

public addField(array<string, array<string|int, mixed>|string>|string $fields) : Forge
Parameters
$fields : array<string, array<string|int, mixed>|string>|string

Field array or Field string

Return values
Forge

addForeignKey()

Add Foreign Key

public addForeignKey([mixed $fieldName = '' ][, string $tableName = '' ][, mixed $tableField = '' ][, string $onUpdate = '' ][, string $onDelete = '' ][, string $fkName = '' ]) : Forge
Parameters
$fieldName : mixed = ''
$tableName : string = ''
$tableField : mixed = ''
$onUpdate : string = ''
$onDelete : string = ''
$fkName : string = ''
Return values
Forge

addKey()

Add Key

public addKey(array<string|int, mixed>|string $key[, bool $primary = false ][, bool $unique = false ][, string $keyName = '' ]) : Forge
Parameters
$key : array<string|int, mixed>|string
$primary : bool = false
$unique : bool = false
$keyName : string = ''
Return values
Forge

addPrimaryKey()

Add Primary Key

public addPrimaryKey(array<string|int, mixed>|string $key[, string $keyName = '' ]) : Forge
Parameters
$key : array<string|int, mixed>|string
$keyName : string = ''
Return values
Forge

addUniqueKey()

Add Unique Key

public addUniqueKey(array<string|int, mixed>|string $key[, string $keyName = '' ]) : Forge
Parameters
$key : array<string|int, mixed>|string
$keyName : string = ''
Return values
Forge

createDatabase()

Create database

public createDatabase(string $dbName[, bool $ifNotExists = false ]) : bool
Parameters
$dbName : string
$ifNotExists : bool = false

Whether to add IF NOT EXISTS condition

Return values
bool

createTable()

public createTable(string $table[, bool $ifNotExists = false ][, array<string|int, mixed> $attributes = [] ]) : bool
Parameters
$table : string
$ifNotExists : bool = false
$attributes : array<string|int, mixed> = []

Table attributes

Tags
throws
DatabaseException
Return values
bool

dropColumn()

public dropColumn(string $table, array<string|int, mixed>|string $columnNames) : bool
Parameters
$table : string
$columnNames : array<string|int, mixed>|string

column names to DROP

Tags
throws
DatabaseException
Return values
bool

dropDatabase()

Drop database

public dropDatabase(string $dbName) : bool
Parameters
$dbName : string
Tags
throws
DatabaseException
Return values
bool

dropForeignKey()

Foreign Key Drop

public dropForeignKey(string $table, string $foreignName) : bool
Parameters
$table : string
$foreignName : string
Tags
throws
DatabaseException
Return values
bool

dropKey()

Drop Key

public dropKey(string $table, string $keyName[, bool $prefixKeyName = true ]) : bool
Parameters
$table : string
$keyName : string
$prefixKeyName : bool = true
Tags
throws
DatabaseException
Return values
bool

dropPrimaryKey()

Drop Primary Key

public dropPrimaryKey(string $table[, string $keyName = '' ]) : bool
Parameters
$table : string
$keyName : string = ''
Return values
bool

dropTable()

public dropTable(string $tableName[, bool $ifExists = false ][, bool $cascade = false ]) : bool
Parameters
$tableName : string
$ifExists : bool = false
$cascade : bool = false
Tags
throws
DatabaseException
Return values
bool

modifyColumn()

public modifyColumn(string $table, array<string, array<string|int, mixed>|string>|string $fields) : bool
Parameters
$table : string
$fields : array<string, array<string|int, mixed>|string>|string

Field array or Field string

Tags
throws
DatabaseException
Return values
bool

processIndexes()

Executes Sql to add indexes without createTable

public processIndexes(string $table) : bool
Parameters
$table : string
Return values
bool

renameTable()

public renameTable(string $tableName, string $newTableName) : bool
Parameters
$tableName : string
$newTableName : string
Tags
throws
DatabaseException
Return values
bool

reset()

Resets table creation vars

public reset() : mixed

_alterTable()

protected _alterTable(string $alterType, string $table, array<string|int, mixed>|string $processedFields) : array<string|int, mixed>|string|null
Parameters
$alterType : string
$table : string
$processedFields : array<string|int, mixed>|string

Processed column definitions or column names to DROP

Tags
phpstan-return

($alterType is 'DROP' ? string : list|null)

Return values
array<string|int, mixed>|string|null

_attributeAutoIncrement()

Field attribute AUTO_INCREMENT

protected _attributeAutoIncrement(array<string|int, mixed> &$attributes, array<string|int, mixed> &$field) : mixed
Parameters
$attributes : array<string|int, mixed>
$field : array<string|int, mixed>

_attributeDefault()

protected _attributeDefault(array<string|int, mixed> &$attributes, array<string|int, mixed> &$field) : mixed
Parameters
$attributes : array<string|int, mixed>
$field : array<string|int, mixed>

_attributeType()

Field attribute TYPE

protected _attributeType(array<string|int, mixed> &$attributes) : mixed

Performs a data type mapping between different databases.

Parameters
$attributes : array<string|int, mixed>

_attributeUnique()

protected _attributeUnique(array<string|int, mixed> &$attributes, array<string|int, mixed> &$field) : mixed
Parameters
$attributes : array<string|int, mixed>
$field : array<string|int, mixed>

_attributeUnsigned()

Depending on the unsigned property value:

protected _attributeUnsigned(array<string|int, mixed> &$attributes, array<string|int, mixed> &$field) : mixed
  • 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
$attributes : array<string|int, mixed>
$field : array<string|int, mixed>

_createTable()

protected _createTable(string $table, bool $ifNotExists, array<string|int, mixed> $attributes) : string

$ifNotExists is no longer used, and will be removed.

Parameters
$table : string
$ifNotExists : bool
$attributes : array<string|int, mixed>

Table attributes

Return values
string

SQL string

_createTableAttributes()

protected _createTableAttributes(array<string|int, mixed> $attributes) : string
Parameters
$attributes : array<string|int, mixed>
Return values
string

_dropKeyAsConstraint()

Constructs sql to check if key is a constraint.

protected _dropKeyAsConstraint(string $table, string $constraintName) : string
Parameters
$table : string
$constraintName : string
Return values
string

_dropTable()

Generates a platform-specific DROP TABLE string

protected _dropTable(string $table, bool $ifExists, bool $cascade) : bool|string
Parameters
$table : string
$ifExists : bool
$cascade : bool
Return values
bool|string

_processColumn()

Process column

protected _processColumn(array<string|int, mixed> $processedField) : string
Parameters
$processedField : array<string|int, mixed>
Return values
string

_processFields()

Returns $processedFields array from $this->fields data.

protected _processFields([bool $createTable = false ]) : array<string|int, mixed>
Parameters
$createTable : bool = false
Return values
array<string|int, mixed>

_processForeignKeys()

Generates SQL to add foreign keys

protected _processForeignKeys(string $table[, bool $asQuery = false ]) : array<string|int, mixed>
Parameters
$table : string
$asQuery : bool = false

When true recreates table with key, else partial SQL used with CREATE TABLE

Return values
array<string|int, mixed>

_processIndexes()

Generates SQL to add indexes

protected _processIndexes(string $table[, bool $asQuery = false ]) : array<string|int, mixed>
Parameters
$table : string
$asQuery : bool = false

When true returns stand alone SQL, else partial SQL used with CREATE TABLE

Return values
array<string|int, mixed>

_processPrimaryKeys()

Generates SQL to add primary key

protected _processPrimaryKeys(string $table[, bool $asQuery = false ]) : string
Parameters
$table : string
$asQuery : bool = false

When true recreates table with key, else partial SQL used with CREATE TABLE

Return values
string

dropKeyAsConstraint()

Checks if key needs to be dropped as a constraint.

protected dropKeyAsConstraint(string $table, string $constraintName) : bool
Parameters
$table : string
$constraintName : string
Return values
bool

databaseExists()

Determine if a database exists

private databaseExists(string $dbName) : bool
Parameters
$dbName : string
Tags
throws
DatabaseException
Return values
bool

        
On this page

Search results