配置
common/config/main-local.php
<?php
return [
// ...
'components' => [
// ...
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=example',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'tablePrefix' => 'x_',
// 可以让数据库字段的类型与取出的类型一致
'attributes' => [
PDO::ATTR_STRINGIFY_FETCHES => false,
// 但是这一行可能引起异常
PDO::ATTR_EMULATE_PREPARES => false
]
],
],
// ...
];