zoukankan      html  css  js  c++  java
  • Yii框架基础增删查改

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

  • 相关阅读:
    jar命令
    python的实例方法,类方法和静态方法区别
    修饰器学习
    人生感悟的句子
    html+css学习
    url编码
    正向代理和反向代理
    web基础
    dns解析域名过程
    关于csrf
  • 原文地址:https://www.cnblogs.com/whel0923/p/10192557.html
Copyright © 2011-2022 走看看