CodeIgniter v4.5 API

Forge extends Forge
in package

Forge for SQLSRV

Table of Contents

Properties

$charset  : string
Character set used.
$checkDatabaseExistStr  : string
CHECK DATABASE EXIST statement
$createDatabaseIfStr  : string
CREATE DATABASE IF statement
$createDatabaseStr  : string
CREATE DATABASE IF statement
$createTableIfStr  : string
CREATE TABLE IF statement
$createTableKeys  : bool
CREATE TABLE keys flag
$createTableStr  : string
CREATE TABLE statement
$db  : BaseConnection
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  : string
RENAME TABLE statement
$uniqueKeys  : array<string|int, mixed>
List of unique keys.
$unsigned  : array<string|int, mixed>
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
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()  : false|array<int, string>|string
_attributeAutoIncrement()  : mixed
Field attribute AUTO_INCREMENT
_attributeDefault()  : mixed
_attributeType()  : mixed
Performs a data type mapping between different databases.
_attributeUnique()  : mixed
_attributeUnsigned()  : mixed
Depending on the unsigned property value:
_createTable()  : string
_createTableAttributes()  : string
CREATE TABLE attributes
_dropIndex()  : mixed
Drop index for table
_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

$charset

Character set used.

protected string $charset = ''

$checkDatabaseExistStr

CHECK DATABASE EXIST statement

protected string $checkDatabaseExistStr = 'IF DB_ID( %s ) IS NOT NULL SELECT 1'

$createDatabaseIfStr

CREATE DATABASE IF statement

protected string $createDatabaseIfStr = "DECLARE @DBName VARCHAR(255) = '%s'\nDECLARE @SQL VARCHAR(max) = 'IF DB_ID( ''' + @DBName + ''' ) IS NULL CREATE DATABASE %s'\nEXEC( @SQL )"
Tags
todo

missing charset, collat & check for existent

$createDatabaseStr

CREATE DATABASE IF statement

protected string $createDatabaseStr = 'CREATE DATABASE %s '
Tags
todo

missing charset & collat

$createTableIfStr

CREATE TABLE IF statement

This is no longer used.

protected string $createTableIfStr

$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

$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

$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 = []

$uniqueKeys

List of unique keys.

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

$unsigned

UNSIGNED support

protected array<string|int, mixed> $unsigned = ['TINYINT' => 'SMALLINT', 'SMALLINT' => 'INT', 'INT' => 'BIGINT', 'REAL' => 'FLOAT']

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([array<int, string>|string $fieldName = '' ][, string $tableName = '' ][, array<int, string>|string $tableField = '' ][, string $onUpdate = '' ][, string $onDelete = '' ][, string $fkName = '' ]) : Forge
Parameters
$fieldName : array<int, string>|string = ''
$tableName : string = ''
$tableField : array<int, string>|string = ''
$onUpdate : string = ''
$onDelete : string = ''
$fkName : string = ''
Tags
throws
DatabaseException
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

Tags
throws
DatabaseException
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()

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) : false|array<int, string>|string
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|false)

Return values
false|array<int, string>|string

SQL string or false

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

Performs a data type mapping between different databases.

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

CREATE TABLE attributes

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

_dropIndex()

Drop index for table

protected _dropIndex(string $table, object $indexData) : mixed
Parameters
$table : string
$indexData : object

_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
Tags
todo

Support for cascade

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 returns stand alone SQL, 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 returns stand alone SQL, 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