ColumnSchema
API reference › yii › db › mysql › ColumnSchema
Represents the metadata of a column in a MySQL database table.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$allowNull | bool | Whether this column can be null. Default: false. | yii\ |
$autoIncrement | bool | Whether this column is auto-incremental Default: false. | yii\ |
$comment | string| | Comment of this column. Default: null. | yii\ |
$dbType | string | The DB type of this column. Default: ''. | yii\ |
$defaultValue | mixed | Default value of this column Default: null. | yii\ |
$enumValues | array| | Enumerable values. Default: null. | yii\ |
$isDefaultExpression | bool | Whether MySQL reports the column default as an expression (DEFAULT_GENERATED). Default: false. Available since 22.0. | ColumnSchema |
$isPrimaryKey | bool| | Whether this column is a primary key Default: null. | yii\ |
$name | string | Name of this column (without quotes). Default: ''. | yii\ |
$phpType | string | The PHP type of this column. Default: ''. | yii\ |
$precision | int| | Precision of the column data, if it is numeric. Default: null. | yii\ |
$scale | int| | Scale of the column data, if it is numeric. Default: null. | yii\ |
$size | int| | Display size of the column. Default: null. | yii\ |
$type | string | Abstract type of this column. Default: ''. | yii\ |
$unsigned | bool | Whether this column is unsigned. Default: false. | yii\ |
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 MySQL column default value 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. | yii\ |
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. | yii\ |
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 MySQL column default value to its PHP representation.
Handles MySQL-specific default value formats:
nulltonull.CURRENT_TIMESTAMP/current_timestamp()on temporal columns (timestamp,datetime,date,time) to anExpression, preserving any declared fractional-seconds precision such asCURRENT_TIMESTAMP(3).- quoted string literals on
textandblobcolumns, 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_ESCAPESare resolved.jsoncolumns are exempt. - remaining expression defaults flagged through
$isDefaultExpressionto anExpression. jsondefaults without the flag to their decoded value when the string is valid JSON, or to anExpressionotherwise; MariaDB reports expression-form defaults without metadata.- remaining
textdefaults without the flag to anExpression, preserving MariaDB’s expression-form SQL. - bit defaults (
b'...') when$dbTypestarts withbitto their integer value viabindec(). - 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
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Default value in the format reported by SHOW FULL COLUMNS. |
Returns
mixed: Converted value.
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