How to convert INT type of Yii2 database to PHP type
This article mainly explains "how to convert the INT type of Yii2 database to PHP type". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to convert the INT type of Yii2 database to PHP type.
When Yii2 converts the int type of the database to the php type, it decides whether it is integer or string based on the server environment.
If it is a 32-bit server, PHP_INT_SIZE=4, 64-bit server, PHP_INT_SIZE=8.
That is, if the int type of DB exceeds the int maximum of PHP, it will be converted to string.
If ($column- > type = 'bigint') {return PHP_INT_SIZE = 8 & &! $column- > unsigned? 'integer':' string';} elseif ($column- > type = 'integer') {return PHP_INT_SIZE = 4 & & $column- > unsigned? 'string':' integer';}
Source code: yii2\ db\ Schema.php
/ * Extracts the PHP type from abstract DB type. * @ param ColumnSchema $column the column schema information * @ return string PHP type name * / protected function getColumnPhpType ($column) {static $typeMap = [/ / abstract type = > php type self::TYPE_TINYINT = > 'integer', self::TYPE_SMALLINT = >' integer', self::TYPE_INTEGER = > 'integer', self::TYPE_BIGINT = >' integer', self::TYPE_BOOLEAN = > 'boolean' Self::TYPE_FLOAT = > 'double', self::TYPE_DOUBLE = >' double', self::TYPE_BINARY = > 'resource', self::TYPE_JSON = >' array',] If (isset ($typeMap [$column- > type]) {if ($column- > type = 'bigint') {return PHP_INT_SIZE = 8 & &! $column- > unsigned? 'integer':' string';} elseif ($column- > type = 'integer') {return PHP_INT_SIZE = 4 & & $column- > unsigned? 'string':' integer';} return $typeMap [$column- > type];} return 'string';} so far, I believe you have a deeper understanding of "how to convert the INT type of Yii2 database to PHP type". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!