# 数据库操作 * * * * * **注意:此处的代码仅为业务逻辑层进行数据库操作的部分参考代码** **保存数据** ~~~ $data['nickname'] = $data['username']; $data['leader_id'] = MEMBER_ID; $data['is_inside'] = DATA_NORMAL; $result = $this->modelMember->setInfo($data); ~~~ **新增数据** ~~~ $data = ['name' => $filename, 'path' => $file_dir_name. SYS_DS_PROS . $filename, 'sha1' => $sha1]; $result = $this->modelFile->addInfo($data); ~~~ **更新数据** ~~~ $where = array('name' => $name); $this->modelConfig->updateInfo($where, ['value' => $value]); ~~~ **批量保存数据** ~~~ $exe_log_array = require $exe_log_path; if (empty($exe_log_array) || DATA_NORMAL == $exe_log_array) : return [RESULT_ERROR, '日志文件为空']; endif; $this->modelExeLog->setList($exe_log_array) && file_put_contents($exe_log_path, ''); ~~~ **设置某个字段值** ~~~ $v['rules'] = arr2str(array_values($rules_arr)); $this->modelAuthGroup->setFieldValue(['id' => $v['id']], 'rules', $v['rules']); ~~~ **删除数据** ~~~ /** * 友情链接删除 */ public function blogrollDel($where = []) { $result = $this->modelBlogroll->deleteInfo($where); $result && action_log('删除', '友情链接删除' . ',where:' . http_build_query($where)); return $result ? [RESULT_SUCCESS, '删除成功'] : [RESULT_ERROR, $this->modelBlogroll->getError()]; } ~~~ **获取某个字段的值** ~~~ /** * 获取默认页面标题 */ public function getDefaultTitle() { return $this->modelMenu->getValue(['module' => MODULE_NAME, 'url' => URL], 'name'); } ~~~ **获取单条数据** ~~~ /** * 获取驱动信息 */ public function getDriverInfo($where = [], $field = true) { return $this->modelDriver->getInfo($where, $field); } ~~~ **获取列表数据** ~~~ /** * 获取会员列表 */ public function getMemberList($where = [], $field = 'm.*,b.nickname as leader_nickname', $order = '', $paginate = DB_LIST_ROWS) { $this->modelMember->alias('m'); $join = [ [SYS_DB_PREFIX . 'member b', 'm.leader_id = b.id', 'LEFT'], ]; $where['m.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE]; return $this->modelMember->getList($where, $field, $order, $paginate, $join); } ~~~