码迷,mamicode.com
首页 > 其他好文 > 详细

Yii2框架连接华为云dws配置

时间:2019-11-24 09:49:25      阅读:62      评论:0      收藏:0      [点我收藏+]

标签:man   orderby   art   send   eve   erb   info   model   查询   

1、在Yii2框架 /common/db.php

$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;
}

Yii2框架连接华为云dws配置

标签:man   orderby   art   send   eve   erb   info   model   查询   

原文地址:https://blog.51cto.com/11315052/2452774

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!