Yii-2查询int变string解决

Posted 一个人的孤独自白

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Yii-2查询int变string解决相关的知识,希望对你有一定的参考价值。

 

 

原因是PDO以string查询数据导致。

这个与YII没关系,是PDO的默认处理,解决方法只需在配置中的db配置中加上attributes的相关配置就行了,如下:

‘components‘ => [
        ‘db‘ => [
            ‘class‘ => ‘yiidbConnection‘,
            ‘dsn‘ => ‘mysql:host=...‘,
            ‘username‘ => ‘...‘,
            ‘password‘ => ‘...‘,
            ‘charset‘ => ‘utf8‘,
            ‘tablePrefix‘ => ‘‘,
            ‘attributes‘ => [
                PDO::ATTR_STRINGIFY_FETCHES => false,
                PDO::ATTR_EMULATE_PREPARES => false,
            ]
        ],

 

以上是关于Yii-2查询int变string解决的主要内容,如果未能解决你的问题,请参考以下文章