Properties

$name

$name : string

Type

string

$options

$options : array

Type

array

$columns

$columns : array

Type

array

$indexes

$indexes : array

Type

array

$data

$data : array

Type

array

Methods

__construct()

__construct(string  $name, array  $options = array(), \Phinx\Db\Adapter\AdapterInterface  $adapter = null) 

Class Constuctor.

Parameters

string $name

Table Name

array $options

Options

\Phinx\Db\Adapter\AdapterInterface $adapter

Database Adapter

setName()

setName(string  $name) : \Phinx\Db\Table

Sets the table name.

Parameters

string $name

Table Name

Returns

\Phinx\Db\Table

getName()

getName() : string

Gets the table name.

Returns

string

setOptions()

setOptions(array  $options) : \Phinx\Db\Table

Sets the table options.

Parameters

array $options

Returns

\Phinx\Db\Table

getOptions()

getOptions() : array

Gets the table options.

Returns

array

exists()

exists() : boolean

Does the table exist?

Returns

boolean

drop()

drop() : void

Drops the database table.

rename()

rename(string  $newTableName) : \Phinx\Db\Table

Renames the database table.

Parameters

string $newTableName

New Table Name

Returns

\Phinx\Db\Table

setColumns()

setColumns(array  $columns) : \Phinx\Db\Table

Sets an array of columns waiting to be committed.

Use setPendingColumns

Parameters

array $columns

Columns

Returns

\Phinx\Db\Table

getColumns()

getColumns() : array<mixed,\Phinx\Db\Table\Column>

Gets an array of the table columns.

Returns

array<mixed,\Phinx\Db\Table\Column>

setPendingColumns()

setPendingColumns(array  $columns) : \Phinx\Db\Table

Sets an array of columns waiting to be committed.

Parameters

array $columns

Columns

Returns

\Phinx\Db\Table

getPendingColumns()

getPendingColumns() : array<mixed,\Phinx\Db\Table\Column>

Gets an array of columns waiting to be committed.

Returns

array<mixed,\Phinx\Db\Table\Column>

setIndexes()

setIndexes(array  $indexes) : \Phinx\Db\Table

Sets an array of columns waiting to be indexed.

Parameters

array $indexes

Indexes

Returns

\Phinx\Db\Table

getIndexes()

getIndexes() : array

Gets an array of indexes waiting to be committed.

Returns

array

setForeignKeys()

setForeignKeys(array<mixed,\Phinx\Db\Table\ForeignKey>  $foreignKeys) : \Phinx\Db\Table

Sets an array of foreign keys waiting to be commited.

Parameters

array<mixed,\Phinx\Db\Table\ForeignKey> $foreignKeys

foreign keys

Returns

\Phinx\Db\Table

getForeignKeys()

getForeignKeys() : array|array<mixed,\Phinx\Db\Table\ForeignKey>

Gets an array of foreign keys waiting to be commited.

Returns

array|array<mixed,\Phinx\Db\Table\ForeignKey>

setData()

setData(array  $data) : \Phinx\Db\Table

Sets an array of data to be inserted.

Parameters

array $data

Data

Returns

\Phinx\Db\Table

getData()

getData() : array

Gets the data waiting to be inserted.

Returns

array

reset()

reset() : void

Resets all of the pending table changes.

addColumn()

addColumn(string|\Phinx\Db\Table\Column  $columnName, string  $type = null, array  $options = array()) : \Phinx\Db\Table

Add a table column.

Type can be: string, text, integer, float, decimal, datetime, timestamp, time, date, binary, boolean.

Valid options can be: limit, default, null, precision or scale.

Parameters

string|\Phinx\Db\Table\Column $columnName

Column Name

string $type

Column Type

array $options

Column Options

Throws

\RuntimeException
\InvalidArgumentException

Returns

\Phinx\Db\Table

removeColumn()

removeColumn(string  $columnName) : \Phinx\Db\Table

Remove a table column.

Parameters

string $columnName

Column Name

Returns

\Phinx\Db\Table

renameColumn()

renameColumn(string  $oldName, string  $newName) : \Phinx\Db\Table

Rename a table column.

Parameters

string $oldName

Old Column Name

string $newName

New Column Name

Returns

\Phinx\Db\Table

changeColumn()

changeColumn(string  $columnName, string|\Phinx\Db\Table\Column  $newColumnType, array  $options = array()) : \Phinx\Db\Table

Change a table column type.

Parameters

string $columnName

Column Name

string|\Phinx\Db\Table\Column $newColumnType

New Column Type

array $options

Options

Returns

\Phinx\Db\Table

hasColumn()

hasColumn(string  $columnName, array  $options = array()) : boolean

Checks to see if a column exists.

Parameters

string $columnName

Column Name

array $options

Options

Returns

boolean

addIndex()

addIndex(string|array|\Phinx\Db\Table\Index  $columns, array  $options = array()) : \Phinx\Db\Table

Add an index to a database table.

In $options you can specific unique = true/false or name (index name).

Parameters

string|array|\Phinx\Db\Table\Index $columns

Table Column(s)

array $options

Index Options

Returns

\Phinx\Db\Table

removeIndex()

removeIndex(array  $columns, array  $options = array()) : \Phinx\Db\Table

Removes the given index from a table.

Parameters

array $columns

Columns

array $options

Options

Returns

\Phinx\Db\Table

removeIndexByName()

removeIndexByName(string  $name) : \Phinx\Db\Table

Removes the given index identified by its name from a table.

Parameters

string $name

Index name

Returns

\Phinx\Db\Table

hasIndex()

hasIndex(string|array  $columns, array  $options = array()) : boolean

Checks to see if an index exists.

Parameters

string|array $columns

Columns

array $options

Options

Returns

boolean

addForeignKey()

addForeignKey(string|array  $columns, string|\Phinx\Db\Table  $referencedTable, string|array  $referencedColumns = array('id'), array  $options = array()) : \Phinx\Db\Table

Add a foreign key to a database table.

In $options you can specify on_delete|on_delete = cascade|no_action .., on_update, constraint = constraint name.

Parameters

string|array $columns

Columns

string|\Phinx\Db\Table $referencedTable

Referenced Table

string|array $referencedColumns

Referenced Columns

array $options

Options

Returns

\Phinx\Db\Table

dropForeignKey()

dropForeignKey(string|array  $columns, null|string  $constraint = null) : \Phinx\Db\Table

Removes the given foreign key from the table.

Parameters

string|array $columns

Column(s)

null|string $constraint

Constraint names

Returns

\Phinx\Db\Table

hasForeignKey()

hasForeignKey(string|array  $columns, null|string  $constraint = null) : boolean

Checks to see if a foreign key exists.

Parameters

string|array $columns

Column(s)

null|string $constraint

Constraint names

Returns

boolean

addTimestamps()

addTimestamps(string  $createdAtColumnName = 'created_at', string  $updatedAtColumnName = 'updated_at') : \Phinx\Db\Table

Add timestamp columns created_at and updated_at to the table.

Parameters

string $createdAtColumnName
string $updatedAtColumnName

Returns

\Phinx\Db\Table

insert()

insert(  $data) : \Phinx\Db\Table

Insert data into the table.

Parameters

$data

array of data in the form: array( array("col1" => "value1", "col2" => "anotherValue1"), array("col2" => "value2", "col2" => "anotherValue2"), ) or array("col1" => "value1", "col2" => "anotherValue1")

Returns

\Phinx\Db\Table

create()

create() : void

Creates a table from the object instance.

update()

update() : void

Updates a table from the object instance.

Throws

\RuntimeException

saveData()

saveData() : void

Commit the pending data waiting for insertion.

save()

save() : void

Commits the table changes.

If the table doesn't exist it is created otherwise it is updated.