本文实例讲述了yii2.0框架数据库操作。分享给大家供大家参考,具体如下:
添加
$id = \yii::$app-&g中国公安人民大学t;db-善假于物>createcommand()->inrt('表名',['car_num' => $car_num, 'lg_shop_id' => $shop_id])->execute();batchinrt():一次添加多行// table name, column names, column valuesyii::$app->db->createcommand()->batchinrt('ur', ['name', 'age'], [ ['tom', 30], ['jane', 20], ['linda', 25],])->execute();
修改
// update (table name, column values, condition)yii::$app->db->createcommand()->update('ur', ['status' => 1], 'age > 30')->execute();
删除
// delete (table name, condition)少林鹰爪功yii::$app->db->createcommand()->delete('ur', 'status = 0')->execute();
查询条件
$status = 10;$arch = 'yii';$query->where(['status' => $status]);if (!empty($arch)) { $query->andwhere(['like', 'title', $arch]);}
如果 $arch 不为空,那么将会生成如下 sql 语句:
... where (`status` = 10) and (`title` like '%yii%')
查询以及打印查询sql
$query = ne教室标语w query(); $query->from('{{%shop_info}}'); $query->where('shop_type=1'); $query->lect('shop_name'); $rea = $query-&g芳草萋萋的意思是什么t;all();//查询 $res = $query->createcommand();//打印sql echo $res->sql;die; var_dump($rea);die;
本文发布于:2023-04-08 16:51:21,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/0704c384bbff1c9c1c83bb88075c625c.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:yii2.0框架数据库操作简单示例【添加,修改,删除,查询,打印等】.doc
本文 PDF 下载地址:yii2.0框架数据库操作简单示例【添加,修改,删除,查询,打印等】.pdf
留言与评论(共有 0 条评论) |