Forge
extends Forge
in package
Forge for MySQLi
Table of Contents
Properties
- $_quoted_table_options : array<string|int, mixed>
- Table Options list which required to be quoted
- $_unsigned : array<string|int, mixed>
- UNSIGNED support
- $charset : string
- Character set used.
- $checkDatabaseExistStr : string
- CHECK DATABASE EXIST statement
- $createDatabaseIfStr : string
- CREATE DATABASE IF statement
- $createDatabaseStr : string
- CREATE DATABASE statement
- $createTableIfStr : bool|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 : 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
- 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<int, string>|string
- ALTER TABLE
- _attributeAutoIncrement() : mixed
- _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
- _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
$_quoted_table_options
Table Options list which required to be quoted
protected
array<string|int, mixed>
$_quoted_table_options
= ['COMMENT', 'COMPRESSION', 'CONNECTION', 'DATA DIRECTORY', 'INDEX DIRECTORY', 'ENCRYPTION', 'PASSWORD']
$_unsigned
UNSIGNED support
protected
array<string|int, mixed>
$_unsigned
= ['TINYINT', 'SMALLINT', 'MEDIUMINT', 'INT', 'INTEGER', 'BIGINT', 'REAL', 'DOUBLE', 'DOUBLE PRECISION', 'FLOAT', 'DECIMAL', 'NUMERIC']
$charset
Character set used.
protected
string
$charset
= ''
$checkDatabaseExistStr
CHECK DATABASE EXIST statement
protected
string
$checkDatabaseExistStr
$createDatabaseIfStr
CREATE DATABASE IF statement
protected
string
$createDatabaseIfStr
= 'CREATE DATABASE IF NOT EXISTS %s CHARACTER SET %s COLLATE %s'
$createDatabaseStr
CREATE DATABASE statement
protected
string
$createDatabaseStr
= 'CREATE DATABASE %s CHARACTER SET %s COLLATE %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
= true
Whether table keys are created from within the CREATE TABLE statement.
$createTableStr
CREATE TABLE statement
protected
string
$createTableStr
= "%s %s (%s\n)"
$db
The active database connection.
protected
BaseConnection
$db
$default
DEFAULT value representation in CREATE/ALTER TABLE statements
protected
false|string
$default
= ' DEFAULT '
$dropConstraintStr
DROP CONSTRAINT statement
protected
string
$dropConstraintStr
= 'ALTER TABLE %s DROP FOREIGN KEY %s'
$dropDatabaseStr
DROP DATABASE statement
protected
false|string
$dropDatabaseStr
= 'DROP DATABASE %s'
$dropIndexStr
DROP INDEX statement
protected
string
$dropIndexStr
= 'DROP INDEX %s ON %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
__construct()
Constructor.
public
__construct(BaseConnection $db) : mixed
Parameters
- $db : BaseConnection
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
Return values
booladdField()
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
ForgeaddForeignKey()
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
Return values
ForgeaddKey()
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
ForgeaddPrimaryKey()
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
ForgeaddUniqueKey()
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
ForgecreateDatabase()
Create database
public
createDatabase(string $dbName[, bool $ifNotExists = false ]) : bool
Parameters
- $dbName : string
- $ifNotExists : bool = false
-
Whether to add IF NOT EXISTS condition
Tags
Return values
boolcreateTable()
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
Return values
booldropColumn()
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
Return values
booldropDatabase()
Drop database
public
dropDatabase(string $dbName) : bool
Parameters
- $dbName : string
Tags
Return values
booldropForeignKey()
public
dropForeignKey(string $table, string $foreignName) : bool
Parameters
- $table : string
- $foreignName : string
Tags
Return values
booldropKey()
Drop Key
public
dropKey(string $table, string $keyName[, bool $prefixKeyName = true ]) : bool
Parameters
- $table : string
- $keyName : string
- $prefixKeyName : bool = true
Return values
booldropPrimaryKey()
Drop Primary Key
public
dropPrimaryKey(string $table[, string $keyName = '' ]) : bool
Parameters
- $table : string
- $keyName : string = ''
Return values
booldropTable()
public
dropTable(string $tableName[, bool $ifExists = false ][, bool $cascade = false ]) : bool
Parameters
- $tableName : string
- $ifExists : bool = false
- $cascade : bool = false
Tags
Return values
boolgetConnection()
Provides access to the forge's current database connection.
public
getConnection() : ConnectionInterface
Return values
ConnectionInterfacemodifyColumn()
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
Return values
boolprocessIndexes()
Executes Sql to add indexes without createTable
public
processIndexes(string $table) : bool
Parameters
- $table : string
Return values
boolrenameTable()
public
renameTable(string $tableName, string $newTableName) : bool
Parameters
- $tableName : string
- $newTableName : string
Tags
Return values
boolreset()
Resets table creation vars
public
reset() : mixed
_alterTable()
ALTER TABLE
protected
_alterTable(string $alterType, string $table, array<string|int, mixed>|string $processedFields) : array<int, string>|string
Parameters
- $alterType : string
-
ALTER type
- $table : string
-
Table name
- $processedFields : array<string|int, mixed>|string
-
Processed column definitions or column names to DROP
Tags
Return values
array<int, string>|string —SQL string
_attributeAutoIncrement()
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>
-
Associative array of table attributes
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 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
stringdropKeyAsConstraint()
Checks if key needs to be dropped as a constraint.
protected
dropKeyAsConstraint(string $table, string $constraintName) : bool
Parameters
- $table : string
- $constraintName : string
Return values
booldatabaseExists()
Determine if a database exists
private
databaseExists(string $dbName) : bool
Parameters
- $dbName : string