Avolutions\Database\Table
The table class provides a bunch of methods to perform schema changes on database tables.
Constants
Property | Value | Description |
---|---|---|
CASCADE | 'CASCADE' | A constant for the string "CASCADE" |
INDEX | 'INDEX' | A constant for the string "INDEX" |
NO_ACTION | 'NO ACTION' | A constant for the string "NO ACTION" |
PRIMARY | 'PRIMARY KEY' | A constant for the string "PRIMARY KEY" |
RESTRICT | 'RESTRICT' | A constant for the string "RESTRICT" |
SET_NULL | 'SET NULL' | A constant for the string "SET NULL" |
UNIQUE | 'UNIQUE' | A constant for the string "UNIQUE" |
Methods
Method | Visibility | Description |
---|---|---|
__construct() | public | Creates a new Table object. |
addColumn() | public | Adds a new column to an existing table. |
addForeignKeyConstraint() | public | Adds a new foreign key constraint to the table. |
addIndex() | public | Adds a new index to an existing table. |
create() | public | Creates a new database table if not exists. |
removeColumn() | public | Removes a column from an existing table. |
Constant Details
Method Details
__construct()
Creates a new Table object.
public
__construct(Database $Database, string $name) : mixed
Parameters
Database
$Database
Database instance.
string
$name
Name of the table.
addColumn()
Adds a new column to an existing table.
public
addColumn(Column $Column[, string|null $after = null ]) : mixed
Parameters
Column
$Column
A Column object to add to the table.
string|null
$after
(optional)
The name of an existing column to add the new Column after it.
Return values
mixed Adds a new column to an existing table.addForeignKeyConstraint()
Adds a new foreign key constraint to the table.
public
addForeignKeyConstraint(string $columnName, string $referenceTableName, string $referenceColumnName[, string $onDelete = Table::RESTRICT ][, string $onUpdate = Table::RESTRICT ][, string|null $constraintName = null ]) : mixed
Parameters
string
$columnName
The name of the column.
string
$referenceTableName
The name of the referenced table.
string
$referenceColumnName
The name of the referenced column.
string
$onDelete
(optional)
The operation that will be performed on delete, one of the following constants should be used: RESTRICT, CASCADE, SET_NULL, NO_ACTION.
string
$onUpdate
(optional)
The operation that will be performed on update, one of the following constants should be used: RESTRICT, CASCADE, SET_NULL, NO_ACTION.
string|null
$constraintName
(optional)
The name of the constraint.
Return values
mixed Adds a new foreign key constraint to the table.addIndex()
Adds a new index to an existing table.
public
addIndex(string $indexType, array<string|int, mixed> $columnNames[, string|null $indexName = null ]) : mixed
Parameters
string
$indexType
The type of the index, one of the following constants should be used: INDEX, PRIMARY, UNIQUE.
array<string|int, mixed>
$columnNames
An array with one or more column names which are included in the index.
string|null
$indexName
(optional)
The name of the index.