Yii2框架连接postgreSql
1、配置连接postgresql的连接信息:
$dev = [ ‘class‘ => ‘yii\db\Connection‘, ‘dsn‘ => ‘pgsql:host=122.112.182.211;port=8000;dbname=sdk_info‘, ‘username‘ => ‘dbadmin‘, ‘password‘ => ‘‘, ‘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(); 查询到一条数据返回
解析结果:``SELECT * FROM "sdk_info"."tb_sdk_vsent" LIMIT 1
$result = $find->select(‘rtt‘)->asArray()->one(); 会查询所有的数据返回一条
解析结果:SELECT "rtt" FROM "sdk_info"."tb_sdk_vsent"
相关推荐
WasteLand 2020-10-18
Allinputs 2020-08-30
Ashes 2020-06-14
caiyiii 2020-06-14
kxguan 2020-06-14
daillo 2020-06-14
一粒沙里的世界 2020-06-14
ruxingli 2020-06-14
csssy00 2020-06-14
阿佐 2020-06-14
NameWFY 2020-05-28
NameWFY 2020-05-26
Robin罗兵 2020-05-16
caiyiii 2020-04-29
wmsjlihuan 2020-04-26
cbao 2020-04-26
csssy00 2020-04-19
igogo00 2020-03-09