• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

CodeIgniter框架实现的数据库增删改查操作

php 搞代码 3年前 (2022-01-21) 15次浏览 已收录 0个评论

这篇文章主要介绍了CI框架(CodeIgniter)实现的数据库增删改查操作,结合实例形式总结分析了CI框架针对mysql数据库增删改查操作的模型、控制器及视图相关定义与使用技巧,需要的朋友可以参考下

本文实例讲述了CI框架(CodeIgniter)实现的数据库增删改查操作。分享给大家供大家参考,具体如下:

controllers下的 cquery.php文件

<?phpclass CQuery extends Controller {  //构造函数  function CQuery() {    parent::Contro<i>*本5文来源gaodai$ma#com搞$$代**码)网@</i><img>搞代码gaodaima</img>ller();//   $this->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,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer);    //判断返回的结果,如果返回true,则调用本页的index方法,不要写 $result == false 因为返回的值未必是false 也有可能是""    if ($result) {      $this->index();    } else {      echo "change failed.";    }  }}

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:CodeIgniter框架实现的数据库增删改查操作
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址