Skip to content
PHP Ecosystem
Explore

ColumnSchema

API reference › yii › db › mysql › ColumnSchema

classyii\db\mysql\ColumnSchema
Extendsyii\db\ColumnSchema » yii\base\BaseObject
Implementsyii\base\Configurable
Since2.0.14.1
Sourceframework/db/mysql/ColumnSchema.php

Represents the metadata of a column in a MySQL database table.

PropertyTypeDescriptionDefined by
$allowNullboolWhether this column can be null. Default: false.yii\db\ColumnSchema
$autoIncrementboolWhether this column is auto-incremental Default: false.yii\db\ColumnSchema
$commentstring|nullComment of this column. Default: null.yii\db\ColumnSchema
$dbTypestringThe DB type of this column. Default: ''.yii\db\ColumnSchema
$defaultValuemixedDefault value of this column Default: null.yii\db\ColumnSchema
$enumValuesarray|nullEnumerable values. Default: null.yii\db\ColumnSchema
$isDefaultExpressionboolWhether MySQL reports the column default as an expression (DEFAULT_GENERATED). Default: false. Available since 22.0.ColumnSchema
$isPrimaryKeybool|nullWhether this column is a primary key Default: null.yii\db\ColumnSchema
$namestringName of this column (without quotes). Default: ''.yii\db\ColumnSchema
$phpTypestringThe PHP type of this column. Default: ''.yii\db\ColumnSchema
$precisionint|nullPrecision of the column data, if it is numeric. Default: null.yii\db\ColumnSchema
$scaleint|nullScale of the column data, if it is numeric. Default: null.yii\db\ColumnSchema
$sizeint|nullDisplay size of the column. Default: null.yii\db\ColumnSchema
$typestringAbstract type of this column. Default: ''.yii\db\ColumnSchema
$unsignedboolWhether this column is unsigned. Default: false.yii\db\ColumnSchema
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.yii\base\BaseObject
__get()Returns the value of an object property.yii\base\BaseObject
__isset()Checks if a property is set, i.e. defined and not null.yii\base\BaseObject
__set()Sets value of an object property.yii\base\BaseObject
__unset()Sets an object property to null.yii\base\BaseObject
canGetProperty()Returns a value indicating whether a property can be read.yii\base\BaseObject
canSetProperty()Returns a value indicating whether a property can be set.yii\base\BaseObject
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
dbTypecast()Converts the input value according to $type and $dbType for use in a db query.ColumnSchema
defaultPhpTypecast()Converts a MySQL column default value to its PHP representation.ColumnSchema
hasMethod()Returns a value indicating whether a method is defined.yii\base\BaseObject
hasProperty()Returns a value indicating whether a property is defined.yii\base\BaseObject
init()Initializes the object.yii\base\BaseObject
isType()Returns whether this column uses the given abstract type.yii\db\ColumnSchema
phpTypecast()Converts the input value according to $phpType after retrieval from the database.ColumnSchema
typecast() protectedConverts the input value according to $phpType after retrieval from the database.yii\db\ColumnSchema
public function dbTypecast(mixed $value): mixed

Converts the input value according to $type and $dbType for use in a db query.

If the value is null or an Expression, it will not be converted.

Parameters

ParameterTypeDescription
$valuemixedInput value

Returns

mixed: Converted value. This may also be an array containing the value as the first element and the PDO type as the second element.

public function defaultPhpTypecast(mixed $value): mixed

Converts a MySQL column default value to its PHP representation.

Handles MySQL-specific default value formats:

  • null to null.
  • CURRENT_TIMESTAMP / current_timestamp() on temporal columns (timestamp, datetime, date, time) to an Expression, preserving any declared fractional-seconds precision such as CURRENT_TIMESTAMP(3).
  • quoted string literals on text and blob columns, and on any column flagged through $isDefaultExpression, to their PHP value: the character-set introducer MySQL prepends is discarded and the escape sequences in \yii\db\mysql\DEFAULT_LITERAL_ESCAPES are resolved. json columns are exempt.
  • remaining expression defaults flagged through $isDefaultExpression to an Expression.
  • json defaults without the flag to their decoded value when the string is valid JSON, or to an Expression otherwise; MariaDB reports expression-form defaults without metadata.
  • remaining text defaults without the flag to an Expression, preserving MariaDB’s expression-form SQL.
  • bit defaults (b'...') when $dbType starts with bit to their integer value via bindec().
  • everything else delegates to phpTypecast().

Branch order is significant: MySQL also flags plain CURRENT_TIMESTAMP defaults as DEFAULT_GENERATED, so the normalization above must win over the generic expression wrapping. Flagged defaults carry an extra metadata escape layer (\', \\) that is removed before literal parsing; MariaDB reports the expression verbatim.

Parameters

ParameterTypeDescription
$valuemixedDefault value in the format reported by SHOW FULL COLUMNS.

Returns

mixed: Converted value.

Since

22.0

public function phpTypecast(mixed $value): mixed

Converts the input value according to $phpType after retrieval from the database.

If the value is null or an Expression, it will not be converted.

Parameters

ParameterTypeDescription
$valuemixedInput value

Returns

mixed: Converted value