Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert INT type of Yii2 database to PHP type

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report