ColumnSchema
API reference › yii › db › ColumnSchema
5 subclasses
ColumnSchema class describes the metadata of a column in a database table.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$allowNull | bool | Whether this column can be null. Default: false. | ColumnSchema |
$autoIncrement | bool | Whether this column is auto-incremental Default: false. | ColumnSchema |
$comment | string| | Comment of this column. Default: null. | ColumnSchema |
$dbType | string | The DB type of this column. Default: ''. | ColumnSchema |
$defaultValue | mixed | Default value of this column Default: null. | ColumnSchema |
$enumValues | array| | Enumerable values. Default: null. | ColumnSchema |
$isPrimaryKey | bool| | Whether this column is a primary key Default: null. | ColumnSchema |
$name | string | Name of this column (without quotes). Default: ''. | ColumnSchema |
$phpType | string | The PHP type of this column. Default: ''. | ColumnSchema |
$precision | int| | Precision of the column data, if it is numeric. Default: null. | ColumnSchema |
$scale | int| | Scale of the column data, if it is numeric. Default: null. | ColumnSchema |
$size | int| | Display size of the column. Default: null. | ColumnSchema |
$type | string | Abstract type of this column. Default: ''. | ColumnSchema |
$unsigned | bool | Whether this column is unsigned. Default: false. | ColumnSchema |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__get() | Returns the value of an object property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets value of an object property. | yii\ |
__unset() | Sets an object property to null. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
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\ |
hasProperty() | Returns a value indicating whether a property is defined. | yii\ |
init() | Initializes the object. | yii\ |
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() protected | Converts the input value according to $phpType after retrieval from the database. | ColumnSchema |
Property details
Section titled “Property details”$comment
Section titled “$comment ”public string|null $comment = nullComment of this column.
Not all DBMS support this.
$dbType
Section titled “$dbType ”public string $dbType = ''The DB type of this column.
Possible DB types vary according to the type of DBMS.
$enumValues
Section titled “$enumValues ”public array|null $enumValues = nullEnumerable values.
This is set only if the column is declared to be an enumerable type.
$phpType
Section titled “$phpType ”public string $phpType = ''The PHP type of this column.
Possible PHP types include:
string, boolean, integer, double, array.
$type
Section titled “$type ”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
Section titled “$unsigned ”public bool $unsigned = falseWhether this column is unsigned.
This is only meaningful
when $type is smallint, integer or bigint.
Method details
Section titled “Method details”dbTypecast()
Section titled “dbTypecast() ”public function dbTypecast(mixed $value): mixedConverts 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
| 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()
Section titled “defaultPhpTypecast() ”public function defaultPhpTypecast(mixed $value): mixedConverts 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
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Raw default value from the database schema metadata. |
Returns
mixed: Converted PHP value.
Since
22.0
isType()
Section titled “isType() ”public function isType(string $type): boolReturns 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()
Section titled “phpTypecast() ”public function phpTypecast(mixed $value): mixedConverts 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
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Input value |
Returns
mixed: Converted value
typecast()
Section titled “typecast() ”protected function typecast(mixed $value): mixedConverts 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
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Input value |
Returns
mixed: Converted value
Since
2.0.3