1、使用save()
$model = new ur();$model->name = 'test';$model->phone = '13000000000';$model->email = '123456@qq.com';$model->save();
2、使用createcommand 原生sql
$sql = "inrt into ur (name, phone, email) values ('test', '13000000000', '123456@qq.com')";yii::$app->db->createcommand($sql)->execute();
3、使用createcommand inrt
yii::$app->db->createcommand()->inrt('ur', [ 'name' => 'test', 'phone' => '13000000000', 'email' => '123456@qq.com'])->execute();
4、批量插入
yii::$app->db->createcommand()->batchinrt('ur', ['name', 'phone', 'email'], [ ['test1', '13000000000', '123456@qq.com'], ['test2', '13000000001', '234567@qq.com']])->execute();
1、使用delete()
怏怏不乐的读音$ur = ur::find()->where(['name' => 'test'])->one();$ur->delete();
2、使用deleteall()批量删除
ur::deleteall(['name' => 'test']);
3、使用createcommand delete()
yii::$app->db->createcomma市场营销就业前景nd()->delete('ur', ['name' => 'test'])->execute();
4、使用createcommand 原生sql
$sql = "delete from ur where name = 'test'";yii::$app->db->createcommand($sql)->execute();
1、使用update()
$ur = ur::find()->where(['name' => 'test'])->one();$ur->phone = '13100000000';$ur->update(); // 或者 $ur->save();
2、使用updateall()
ur::updateall(['phone' => '13100000000'], ['name' => 'test']);
3、使用createcommand update()
yii::$app->db->createcommand()->update('ur', ['phone' => '13100000000'], ['name' => 'test'])->11月13日是什么星座;execute();
4、使用createcommand 原生sql
$sql = "update ur t phone = '13100000000' wh高中数学教育论文ere name = 'test'";yii::$app->db->createcommand($sql)->execute();
1、使用model
// 查询一条记录ur::find()->lect(['name', 'phone', 'email'])->where(['phone' => '13000000000'])->andwhere(['like', 'name', 'test'])->one();// 查询一条记录数组返回ur::find()->where(['name' => 'test'])->asarray()->one();// 查询所有记录ur::find()->where(['name' => 'test'])->all();// 查询所有记录数组返回ur::find()->where(['name' => 'test'])->asarray()->all();
2、使用createcommand
// 查询一人工智能技术应用条记录yii::$app->db->createcommand("lect * from ur where name = :name and phone = :phone")->bindvalues([':name' => 'test', ':phone' => '13000000000'])->queryone();// 查询所有记录yii::$app->db->createcommand("lect * from ur where name = :name and phone = :phone")->bindvalues([':name' => 'test', ':phone' => '13000000000'])->queryall();
3、使用yii\db\query()
(new \yii\db\query())->from('ur')->where(['name' => 'test'])->all();
4、子查询
$subquery = (new \yii\db\query())->lect(['id'])->from('ur')->where(['like', 'name', 'test'])->all();(new \yii\db\query())->from('ur')->where(['in', 'id', $subquery])->all();
本文发布于:2023-04-07 07:06:10,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/8583cc4adfb5afd76240ac1813add693.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:Yii2 中常用的增删改查操作总结.doc
本文 PDF 下载地址:Yii2 中常用的增删改查操作总结.pdf
留言与评论(共有 0 条评论) |