1、配置連接postgresql的連接信息:
成都創(chuàng)新互聯(lián)主營蘭西網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,App定制開發(fā),蘭西h5小程序制作搭建,蘭西網(wǎng)站營銷推廣歡迎蘭西等地區(qū)企業(yè)咨詢
$dev = [
'class' => 'yii\db\Connection',
'dsn' => 'pgsql:host=122.112.182.211;port=8000;dbname=sdk_info',
'username' => 'dbadmin',
'password' => 'Styl2018@',
'charset' => 'utf8',
// 'emulatePrepare' => true
];
return $dev;
2、Yii2目錄下,models目錄下新建model:
class TestSdkVsent extends Base
{
public static function getDb()
{
return \Yii::$app->dbDws;
}
public static function tableName()
{
return 'sdk_info.tb_sdk_vsent'; // TODO: Change the autogenerated stub
}
public static function test()
{
$find = static::find();
$result = $find->select('rtt')->limit(1) ->asArray()->one();
return $result;
}
}
3、備注:
$result = $find->select('rtt')->limit(1)->asArray()->one(); 查詢到一條數(shù)據(jù)返回
解析結(jié)果:``SELECT * FROM "sdk_info"."tb_sdk_vsent" LIMIT 1
$result = $find->select('rtt')->asArray()->one(); 會查詢所有的數(shù)據(jù)返回一條
解析結(jié)果:SELECT "rtt" FROM "sdk_info"."tb_sdk_vsent"