Loading

YII框架增删改查常用语句

//实例化db
$db = new \yii\db\Query();
//插入
$db->createCommand()->insert('user', [ 'name' => 'test', 'age' => 30, ])->execute();
//获取最后插入的id
Yii::$app->db->getLastInsertID()
//批量插入 
$db->createCommand()->batchInsert('user', ['name', 'age'], [ ['test01', 30], ['test02', 20], ['test03', 25], ])->execute(); 
//更新
 $db->createCommand()->update('mif_model',$data,$where)->execute(); 
//删除 
$db->createCommand()->delete('user', 'age = 30')->execute();
//获取sql语句
$db->from("$table")->where("$where")->createCommand()->getRawSql();

 

//查询语句

 

posted @ 2018-03-15 15:05  王召波  阅读(277)  评论(0编辑  收藏  举报