加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

CI框架(CodeIgniter)实现的数据库增编削查操纵总结

发布时间:2021-05-25 03:43:53 所属栏目:编程 来源:网络整理
导读:副问题#e# 本篇章节讲授CI框架(CodeIgniter)实现的数据库增编削查操纵。分享给各人供各人参考,详细如下: controllers下的 cquery.php文件 load->database(); } function index() { //挪用model 个中train为外层文件夹 MQuery为model名称 queryList为重命
副问题[/!--empirenews.page--]

本篇章节讲授CI框架(CodeIgniter)实现的数据库增编削查操纵。分享给各人供各人参考,详细如下:

controllers下的 cquery.php文件

load->database(); } function index() { //挪用model 个中train为外层文件夹 MQuery为model名称 queryList为重定名 $this->load->model('train/MQuery','queryList'); //得到返回的功效集 这里确定挪用model中的哪个要领 $result = $this->queryList->queryList(); //将功效集赋给res $this->smarty->assign('res',$result); //跳转到表现页面 $this->smarty->view('train/vquery.tpl'); } //进入新增页面 function addPage() { $this->smarty->view('train/addPage.tpl'); } //新增 function add() { //得到前台数据 //用户名 $memberName = $this->input->post('memberName'); //暗码 $password = $this->input->post('password'); //真实姓名 $userRealName = $this->input->post('userRealName'); //性别 $sex = $this->input->post('sex'); //出生日期 $bornDay = $this->input->post('bornDay'); //e_mail $eMail = $this->input->post('eMail'); //暗码题目 $question = $this->input->post('question'); //暗码谜底 $answer = $this->input->post('answer'); //挪用model $this->load->model('train/MQuery','addRecord'); //向model中的addRecord传值 $result = $this->addRecord->addRecord($memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer); //判定返回的功效,假如返回true,则挪用本页的index要领,不要写 $result == false 由于返回的值未必是false 也有也许是"" if ($result) { $this->index(); } else { echo "add failed."; } } //删除 function deletePage() { //得到ID $deleteID = $this->uri->segment(4); //挪用model $this->load->model('train/MQuery','delRecord'); //将值传入到model的delRecord要领中 $result = $this->delRecord->delRecord($deleteID); //判定返回值 if ($result) { $this->index(); } else { echo "delect failed."; } } //修改先查询 function changePage() { $changeID = $this->uri->segment(4); $this->load->model('train/MQuery','changeRecord'); $result = $this->changeRecord->changeRecord($changeID); //将功效集赋给res $this->smarty->assign('res',$result); //跳转到表现页面 $this->smarty->view('train/changePage.tpl'); } //修改 function change() { //得到前台数据 //ID $ID = $this->input->post('id'); //用户名 $memberName = $this->input->post('memberName'); //暗码 $password = $this->input->post('password'); //真实姓名 $userRealName = $this->input->post('userRealName'); //性别 $sex = $this->input->post('sex'); //出生日期 $bornDay = $this->input->post('bornDay'); //e_mail $eMail = $this->input->post('eMail'); //暗码题目 $question = $this->input->post('question'); //暗码谜底 $answer = $this->input->post('answer'); //挪用model $this->load->model('train/MQuery','change'); //向model中的change传值 $result = $this->change->change($ID,$memberName,不要写 $result == false 由于返回的值未必是false 也有也许是"" if ($result) { $this->index(); } else { echo "change failed."; } } }

models中的 mquery.php 文件

load->database(); } //查询列表 function queryList() { //防备select出的数据存在乱码题目 //mysql_query("SET NAMES GBK"); //SQL语句 $sql = "SELECT ID,member_name,sex,e_mail FROM user_info_t"; //执行SQL $rs = $this->db->query($sql); //将查询功效放入到功效齐集 $result = $rs->result(); //封锁数据库 $this->db->close(); //将功效集返回 return $result; } //新增 function addRecord($memberName,$answer) { //防备select出的数据存在乱码题目 //mysql_query("SET NAMES GBK"); //SQL语句 $sql = "INSERT INTO user_info_t (member_name,password,user_real_name,born_day,e_mail,question,answer) " . "VALUES ('$memberName','$password','$userRealName','$sex','$bornDay','$eMail','$question','$answer')"; //执行SQL $result = $this->db->query($sql); //封锁数据库 $this->db->close(); //返回值 return $result; } //删除 function delRecord($deleteID) { //防备select出的数据存在乱码题目 //mysql_query("SET NAMES GBK"); $sql = "DELETE FROM user_info_t WHERE ID = $deleteID"; $result = $this->db->query($sql); $this->db->close(); return $result; } //修改前查询 function changeRecord($changeID) { //防备select出的数据存在乱码题目 //mysql_query("SET NAMES GBK"); $sql = "SELECT ID,answer FROM user_info_t WHERE ID = $changeID"; //执行SQL $rs = $this->db->query($sql); $result = $rs->row();//$result = $rs[0] //封锁数据库 $this->db->close(); //将功效集返回 return $result; } //修改 function change($ID,$answer) { //防备select出的数据存在乱码题目 //mysql_query("SET NAMES GBK"); //SQL语句 $sql = "update user_info_t set member_name = '$memberName',password = '$password',user_real_name = '$userRealName'," . "sex = '$sex',born_day = '$bornDay',e_mail = '$eMail',question = '$question',answer = '$answer'" . "where ID = $ID"; //执行SQL $result = $this->db->query($sql); //封锁数据库 $this->db->close(); //返回值 return $result; } }

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读