返回一条数据
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');

 

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!