返回一条数据
Country::find()->one();
返回所有数据
Country::find()->all();
返回记录的数量
$country =Country::find()->count();
$model = new Country(); 实例化模型层新增
$model->username = 'zhangsan'; 字段username
$model->password = '123456';
$model->save(); 保存
实例化修改
$country = Country::find()->where(['id'=>'2'])->one(); 查询一条数据
$country->username = '张三';
$country->save();
实例化删除
$country = Country::find()->where(['id'=>'8'])->one();
$country->delete();
使用createCommand()进行新增数据
Yii::$app->db->createCommand()->insert('country',['username'=>'value','password'=>'value'])->execute();
使用createCommand()修改
Yii::$app->db->createCommand()->update('content',['name'=>'value'],'id=1')->execute();
使用createCommand()删除
Yii::$app->db->createCommand()->delete('country','id=9')->execute();
直接删除
Country::deleteAll('id=7');
直接修改
Country::updateAll(['username'=>'root'],'id=3');