yii2框架接入pgSQL(查询不到表The table does not exist: {{%user}})
我是yii2的框架做的系统接的是MySQL数据库,后面因为其他情况又要去接pgSQL,导致遇到上面的情况,我的情况是我的pgSQL数据库下有账号的表两个,我用的是第一个账号下的表,但系统获取的是第二个public账号下的表,导致系统运行要查询表的时候就会报错The table does not exist: {{%user}}.
解决办法:
在yii2项目中的config/db.php中加入以下代码
<?php
return [
'class' => 'yii\db\Connection',
'dsn' => 'pgsql:host=192.168.01.01;port=5432;dbname=test',
'username' => 'test',
'password' => '123456',
'tablePrefix' => 'ts_', //表前缀
'schemaMap' => [
'pgsql'=> [
'class'=>'yii\db\pgsql\Schema',
'defaultSchema' => 'public' //指定系统接pgSQL数据库下哪个账号的表
]
],
];