yii\db\Connection , dsn => pgsql:host=122.112.182.211;port=8000;dbname=sdk_i..."/>
您好,登錄后才能下訂單哦!
1、配置連接postgresql的連接信息:
$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"
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。