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();
//查询语句