Skip to content
PHP Ecosystem
Explore

ColumnSchema

API reference › yii › db › ColumnSchema

classyii\db\ColumnSchema
Extendsyii\base\BaseObject
Implementsyii\base\Configurable
Since2.0
Sourceframework/db/ColumnSchema.php
5 subclasses

ColumnSchema class describes the metadata of a column in a database table.

PropertyTypeDescriptionDefined by
$allowNullboolWhether this column can be null. Default: false.ColumnSchema
$autoIncrementboolWhether this column is auto-incremental Default: false.ColumnSchema
$commentstring|nullComment of this column. Default: null.ColumnSchema
$dbTypestringThe DB type of this column. Default: ''.ColumnSchema
$defaultValuemixedDefault value of this column Default: null.ColumnSchema
$enumValuesarray|nullEnumerable values. Default: null.ColumnSchema
$isPrimaryKeybool|nullWhether this column is a primary key Default: null.ColumnSchema
$namestringName of this column (without quotes). Default: ''.ColumnSchema
$phpTypestringThe PHP type of this column. Default: ''.ColumnSchema
$precisionint|nullPrecision of the column data, if it is numeric. Default: null.ColumnSchema
$scaleint|nullScale of the column data, if it is numeric. Default: null.ColumnSchema
$sizeint|nullDisplay size of the column. Default: null.ColumnSchema
$typestringAbstract type of this column. Default: ''.ColumnSchema
$unsignedboolWhether this column is unsigned. Default: false.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 raw column default value from the database metadata 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.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.ColumnSchema
public string|null $comment = null

Comment of this column.

Not all DBMS support this.

public string $dbType = ''

The DB type of this column.

Possible DB types vary according to the type of DBMS.

public array|null $enumValues = null

Enumerable values.

This is set only if the column is declared to be an enumerable type.

public string $phpType = ''

The PHP type of this column.

Possible PHP types include: string, boolean, integer, double, array.

public string $type = ''

Abstract type of this column.

Possible abstract types include: char, string, text, boolean, smallint, integer, bigint, float, decimal, datetime, timestamp, time, date, binary, and money.

public bool $unsigned = false

Whether this column is unsigned.

This is only meaningful when $type is smallint, integer or bigint.

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 raw column default value from the database metadata to its PHP representation.

The base implementation delegates to phpTypecast(). Driver-specific subclasses override this method to return a PHP literal for recognized literal defaults, or an Expression for defaults the engine reports as expression SQL, such as CURRENT_TIMESTAMP or nextval(...).

Parameters

ParameterTypeDescription
$valuemixedRaw default value from the database schema metadata.

Returns

mixed: Converted PHP value.

Since

22.0

public function isType(string $type): bool

Returns whether this column uses the given abstract type.

Parameters

ParameterTypeDescription
$typestringAbstract column type.

Returns

bool: Whether this column uses the given abstract type.

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

protected function typecast(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

Since

2.0.3