# ColumnSchema

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

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [db](/docs/api/yii/db/index.md) › ColumnSchema

| class | `yii\db\ColumnSchema` |
| --- | --- |
| Extends | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/db/ColumnSchema.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/db/ColumnSchema.php#L20) |

5 subclasses:

- [`yii\db\mssql\ColumnSchema`](/docs/api/yii/db/mssql/columnschema/index.md)
- [`yii\db\mysql\ColumnSchema`](/docs/api/yii/db/mysql/columnschema/index.md)
- [`yii\db\oci\ColumnSchema`](/docs/api/yii/db/oci/columnschema/index.md)
- [`yii\db\pgsql\ColumnSchema`](/docs/api/yii/db/pgsql/columnschema/index.md)
- [`yii\db\sqlite\ColumnSchema`](/docs/api/yii/db/sqlite/columnschema/index.md)

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

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-allowNull"></span>`$allowNull` | `bool` | Whether this column can be null. Default: `false`. | `ColumnSchema` |
| <span id="property-autoIncrement"></span>`$autoIncrement` | `bool` | Whether this column is auto-incremental Default: `false`. | `ColumnSchema` |
| [`$comment`](#property-comment) | `string\|null` | Comment of this column. Default: `null`. | `ColumnSchema` |
| [`$dbType`](#property-dbType) | `string` | The DB type of this column. Default: `''`. | `ColumnSchema` |
| <span id="property-defaultValue"></span>`$defaultValue` | `mixed` | Default value of this column Default: `null`. | `ColumnSchema` |
| [`$enumValues`](#property-enumValues) | `array\|null` | Enumerable values. Default: `null`. | `ColumnSchema` |
| <span id="property-isPrimaryKey"></span>`$isPrimaryKey` | `bool\|null` | Whether this column is a primary key Default: `null`. | `ColumnSchema` |
| <span id="property-name"></span>`$name` | `string` | Name of this column (without quotes). Default: `''`. | `ColumnSchema` |
| [`$phpType`](#property-phpType) | `string` | The PHP type of this column. Default: `''`. | `ColumnSchema` |
| <span id="property-precision"></span>`$precision` | `int\|null` | Precision of the column data, if it is numeric. Default: `null`. | `ColumnSchema` |
| <span id="property-scale"></span>`$scale` | `int\|null` | Scale of the column data, if it is numeric. Default: `null`. | `ColumnSchema` |
| <span id="property-size"></span>`$size` | `int\|null` | Display size of the column. Default: `null`. | `ColumnSchema` |
| [`$type`](#property-type) | `string` | Abstract type of this column. Default: `''`. | `ColumnSchema` |
| [`$unsigned`](#property-unsigned) | `bool` | Whether this column is unsigned. Default: `false`. | `ColumnSchema` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/baseobject/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/baseobject/index.md#method-__get) | Returns the value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/baseobject/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/baseobject/index.md#method-__set) | Sets value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/baseobject/index.md#method-__unset) | Sets an object property to null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`dbTypecast()`](#method-dbTypecast) | Converts the input value according to [`$type`](/docs/api/yii/db/columnschema/index.md#property-type) and [`$dbType`](/docs/api/yii/db/columnschema/index.md#property-dbType) for use in a db query. | `ColumnSchema` |
| [`defaultPhpTypecast()`](#method-defaultPhpTypecast) | Converts a raw column default value from the database metadata to its PHP representation. | `ColumnSchema` |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/baseobject/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/baseobject/index.md#method-hasProperty) | Returns a value indicating whether a property is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/baseobject/index.md#method-init) | Initializes the object. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`isType()`](#method-isType) | Returns whether this column uses the given abstract type. | `ColumnSchema` |
| [`phpTypecast()`](#method-phpTypecast) | Converts the input value according to [`$phpType`](/docs/api/yii/db/columnschema/index.md#property-phpType) after retrieval from the database. | `ColumnSchema` |
| [`typecast()`](#method-typecast) protected | Converts the input value according to [`$phpType`](/docs/api/yii/db/columnschema/index.md#property-phpType) after retrieval from the database. | `ColumnSchema` |

## Property details

### $comment <span id="property-comment"></span>

```php
public string|null $comment = null
```

Comment of this column.

Not all DBMS support this.

### $dbType <span id="property-dbType"></span>

```php
public string $dbType = ''
```

The DB type of this column.

Possible DB types vary according to the type of DBMS.

### $enumValues <span id="property-enumValues"></span>

```php
public array|null $enumValues = null
```

Enumerable values.

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

### $phpType <span id="property-phpType"></span>

```php
public string $phpType = ''
```

The PHP type of this column.

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

### $type <span id="property-type"></span>

```php
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.

### $unsigned <span id="property-unsigned"></span>

```php
public bool $unsigned = false
```

Whether this column is unsigned.

This is only meaningful
when [`$type`](/docs/api/yii/db/columnschema/index.md#property-type) is `smallint`, `integer` or `bigint`.

## Method details

### dbTypecast() <span id="method-dbTypecast"></span>

```php
public function dbTypecast(mixed $value): mixed
```

Converts the input value according to [`$type`](/docs/api/yii/db/columnschema/index.md#property-type) and [`$dbType`](/docs/api/yii/db/columnschema/index.md#property-dbType) for use in a db query.

If the value is null or an [`Expression`](/docs/api/yii/db/expression/index.md), it will not be converted.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | Input 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.

### defaultPhpTypecast() <span id="method-defaultPhpTypecast"></span>

```php
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()`](/docs/api/yii/db/columnschema/index.md#method-phpTypecast). Driver-specific subclasses override this method to
return a PHP literal for recognized literal defaults, or an [`Expression`](/docs/api/yii/db/expression/index.md) for defaults the engine reports
as expression SQL, such as `CURRENT_TIMESTAMP` or `nextval(...)`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | Raw default value from the database schema metadata. |

**Returns**

`mixed`: Converted PHP value.

**Since**

22.0

### isType() <span id="method-isType"></span>

```php
public function isType(string $type): bool
```

Returns whether this column uses the given abstract type.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `string` | Abstract column type. |

**Returns**

`bool`: Whether this column uses the given abstract type.

**Since**

22.0

### phpTypecast() <span id="method-phpTypecast"></span>

```php
public function phpTypecast(mixed $value): mixed
```

Converts the input value according to [`$phpType`](/docs/api/yii/db/columnschema/index.md#property-phpType) after retrieval from the database.

If the value is null or an [`Expression`](/docs/api/yii/db/expression/index.md), it will not be converted.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | Input value |

**Returns**

`mixed`: Converted value

### typecast() <span id="method-typecast"></span>

```php
protected function typecast(mixed $value): mixed
```

Converts the input value according to [`$phpType`](/docs/api/yii/db/columnschema/index.md#property-phpType) after retrieval from the database.

If the value is null or an [`Expression`](/docs/api/yii/db/expression/index.md), it will not be converted.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | Input value |

**Returns**

`mixed`: Converted value

**Since**

2.0.3