Yii2 frame connector configuration Huawei cloud dws

1, the frame /common/db.php Yii2

$dev = [
    'class'    => 'yii\db\Connection',
    'dsn'      => 'pgsql:host=127.0.0.1;port=8000;dbname=info',
    'username' => 'admin',
    'password' => 'admin',
    'charset'  => 'utf8',
    'emulatePrepare' => true,
    'schemaMap' => [
        'pgsql'=> [
            'class'=>'yii\db\pgsql\Schema',
            'defaultSchema' => 'portal' //默认视图
        ]
    ],
    'on afterOpen' => function($event) {
        // $event->sender refers to the DB connection
        $event->sender->createCommand("SET CURRENT_SCHEMA = 'public'")->execute();//执行sql语句设置视图
    }
];

2、在models类
public static function queryEndToEndAudioRecv($params)
{
$start = microtime(true);

    $find = static::find();
    $find->andWhere('log_time>=' . $params['startTime']);
    $find->andWhere('log_time<=' . $params['endTime']);
    $list= $find->select('user_id,recvbr,lost_rate,rcarton,recvuid,log_time')
        ->orderBy('log_time asc');
        ->asArray()
        ->all();

    $sql = $find->createCommand()->getRawSql();//生成查询语句
    $end = microtime(true);
    ll('耗时(秒):' . ($end - $start) . 'sql:' . $sql, 'dwsSql.log');

    return $list;
}

Guess you like

Origin blog.51cto.com/11315052/2452774