CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.7 Red Velvet API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.7
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
      • Dialect
      • Driver
      • Exception
      • Expression
      • Log
      • Retry
      • Schema
      • Statement
      • Type
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Interface TableSchemaInterface

An interface used by database TableSchema objects.

Namespace: Cake\Database\Schema

Constants

  • string
    TYPE_BIGINTEGER ¶
    'biginteger'

    Big Integer column type

  • string
    TYPE_BINARY ¶
    'binary'

    Binary column type

  • string
    TYPE_BINARY_UUID ¶
    'binaryuuid'

    Binary UUID column type

  • string
    TYPE_BOOLEAN ¶
    'boolean'

    Boolean column type

  • string
    TYPE_DATE ¶
    'date'

    Date column type

  • string
    TYPE_DATETIME ¶
    'datetime'

    Datetime column type

  • string
    TYPE_DECIMAL ¶
    'decimal'

    Decimal column type

  • string
    TYPE_FLOAT ¶
    'float'

    Float column type

  • string
    TYPE_INTEGER ¶
    'integer'

    Integer column type

  • string
    TYPE_JSON ¶
    'json'

    JSON column type

  • string
    TYPE_SMALLINTEGER ¶
    'smallinteger'

    Small Integer column type

  • string
    TYPE_STRING ¶
    'string'

    String column type

  • string
    TYPE_TEXT ¶
    'text'

    Text column type

  • string
    TYPE_TIME ¶
    'time'

    Time column type

  • string
    TYPE_TIMESTAMP ¶
    'timestamp'

    Timestamp column type

  • string
    TYPE_TINYINTEGER ¶
    'tinyinteger'

    Tiny Integer column type

  • string
    TYPE_UUID ¶
    'uuid'

    UUID column type

Method Summary

  • addColumn() public

    Add a column to the table.

  • addConstraint() public

    Add a constraint.

  • addIndex() public

    Add an index.

  • baseColumnType() public

    Returns the base type name for the provided column. This represent the database type a more complex class is based upon.

  • columns() public

    Get the column names in the table.

  • constraints() public

    Get the names of all the constraints in the table.

  • defaultValues() public

    Get a hash of columns and their default values.

  • dropConstraint() public

    Remove a constraint.

  • getColumn() public

    Get column data in the table.

  • getColumnType() public

    Returns column type or null if a column does not exist.

  • getConstraint() public

    Read information about a constraint based on name.

  • getIndex() public

    Read information about an index based on name.

  • getOptions() public

    Gets the options for a table.

  • hasAutoincrement() public

    Check whether or not a table has an autoIncrement column defined.

  • hasColumn() public

    Returns true if a column exists in the schema.

  • indexes() public

    Get the names of all the indexes in the table.

  • isNullable() public

    Check whether or not a field is nullable

  • isTemporary() public

    Gets whether the table is temporary in the database.

  • name() public

    Get the name of the table.

  • primaryKey() public

    Get the column(s) used for the primary key.

  • removeColumn() public

    Remove a column from the table schema.

  • setColumnType() public

    Sets the type of a column.

  • setOptions() public

    Sets the options for a table.

  • setTemporary() public

    Sets whether the table is temporary in the database.

  • typeMap() public

    Returns an array where the keys are the column names in the schema and the values the database type they have.

Method Detail

addColumn() ¶ public

addColumn(string $name, array|string $attrs): $this

Add a column to the table.

Attributes

Columns can have several attributes:

  • type The type of the column. This should be one of CakePHP's abstract types.
  • length The length of the column.
  • precision The number of decimal places to store for float and decimal types.
  • default The default value of the column.
  • null Whether or not the column can hold nulls.
  • fixed Whether or not the column is a fixed length column. This is only present/valid with string columns.
  • unsigned Whether or not the column is an unsigned column. This is only present/valid for integer, decimal, float columns.

In addition to the above keys, the following keys are implemented in some database dialects, but not all:

  • comment The comment for the column.
Parameters
string $name

The name of the column

array|string $attrs

The attributes for the column.

Returns
$this

addConstraint() ¶ public

addConstraint(string $name, array $attrs): $this

Add a constraint.

Used to add constraints to a table. For example primary keys, unique keys and foreign keys.

Attributes

  • type The type of constraint being added.
  • columns The columns in the index.
  • references The table, column a foreign key references.
  • update The behavior on update. Options are 'restrict', 'setNull', 'cascade', 'noAction'.
  • delete The behavior on delete. Options are 'restrict', 'setNull', 'cascade', 'noAction'.

The default for 'update' & 'delete' is 'cascade'.

Parameters
string $name

The name of the constraint.

array $attrs

The attributes for the constraint.

Returns
$this

addIndex() ¶ public

addIndex(string $name, array $attrs): $this

Add an index.

Used to add indexes, and full text indexes in platforms that support them.

Attributes

  • type The type of index being added.
  • columns The columns in the index.
Parameters
string $name

The name of the index.

array $attrs

The attributes for the index.

Returns
$this

baseColumnType() ¶ public

baseColumnType(string $column): string|null

Returns the base type name for the provided column. This represent the database type a more complex class is based upon.

Parameters
string $column

The column name to get the base type from

Returns
string|null

The base type name

columns() ¶ public

columns(): string[]

Get the column names in the table.

Returns
string[]

constraints() ¶ public

constraints(): string[]

Get the names of all the constraints in the table.

Returns
string[]

defaultValues() ¶ public

defaultValues(): array

Get a hash of columns and their default values.

Returns
array

dropConstraint() ¶ public

dropConstraint(string $name): $this

Remove a constraint.

Parameters
string $name

Name of the constraint to remove

Returns
$this

getColumn() ¶ public

getColumn(string $name): array|null

Get column data in the table.

Parameters
string $name

The column name.

Returns
array|null

Column data or null.

getColumnType() ¶ public

getColumnType(string $name): string|null

Returns column type or null if a column does not exist.

Parameters
string $name

The column to get the type of.

Returns
string|null

getConstraint() ¶ public

getConstraint(string $name): array|null

Read information about a constraint based on name.

Parameters
string $name

The name of the constraint.

Returns
array|null

Array of constraint data, or null

getIndex() ¶ public

getIndex(string $name): array|null

Read information about an index based on name.

Parameters
string $name

The name of the index.

Returns
array|null

Array of index data, or null

getOptions() ¶ public

getOptions(): array

Gets the options for a table.

Table options allow you to set platform specific table level options. For example the engine type in MySQL.

Returns
array

An array of options.

hasAutoincrement() ¶ public

hasAutoincrement(): bool

Check whether or not a table has an autoIncrement column defined.

Returns
bool

hasColumn() ¶ public

hasColumn(string $name): bool

Returns true if a column exists in the schema.

Parameters
string $name

Column name.

Returns
bool

indexes() ¶ public

indexes(): string[]

Get the names of all the indexes in the table.

Returns
string[]

isNullable() ¶ public

isNullable(string $name): bool

Check whether or not a field is nullable

Missing columns are nullable.

Parameters
string $name

The column to get the type of.

Returns
bool

Whether or not the field is nullable.

isTemporary() ¶ public

isTemporary(): bool

Gets whether the table is temporary in the database.

Returns
bool

The current temporary setting.

name() ¶ public

name(): string

Get the name of the table.

Returns
string

primaryKey() ¶ public

primaryKey(): array

Get the column(s) used for the primary key.

Returns
array

Column name(s) for the primary key. An empty list will be returned when the table has no primary key.

removeColumn() ¶ public

removeColumn(string $name): $this

Remove a column from the table schema.

If the column is not defined in the table, no error will be raised.

Parameters
string $name

The name of the column

Returns
$this

setColumnType() ¶ public

setColumnType(string $name, string $type): $this

Sets the type of a column.

Parameters
string $name

The column to set the type of.

string $type

The type to set the column to.

Returns
$this

setOptions() ¶ public

setOptions(array $options): $this

Sets the options for a table.

Table options allow you to set platform specific table level options. For example the engine type in MySQL.

Parameters
array $options

The options to set, or null to read options.

Returns
$this

setTemporary() ¶ public

setTemporary(bool $temporary): $this

Sets whether the table is temporary in the database.

Parameters
bool $temporary

Whether or not the table is to be temporary.

Returns
$this

typeMap() ¶ public

typeMap(): array

Returns an array where the keys are the column names in the schema and the values the database type they have.

Returns
array
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs