设为首页 加入收藏

TOP

Yii框架基础增删查改
2019-08-23 00:42:02 】 浏览:26
Tags: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');

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇阿里云轻量应用服务器 搭建配置详.. 下一篇laravel中请求用例$request可用的..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目