Yii-2查询int变string解决

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

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

'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=...',
            'username' => '...',
            'password' => '...',
            'charset' => 'utf8',
            'tablePrefix' => '',
            'attributes' => [
                PDO::ATTR_STRINGIFY_FETCHES => false,
                PDO::ATTR_EMULATE_PREPARES => false,
            ]
        ],

猜你喜欢

转载自www.cnblogs.com/-mrl/p/10593527.html