zoukankan      html  css  js  c++  java
  • TP框架 增删查

    TP框架
    添加数据到数据库
    1.使用数组方式添加
    造模型对象

    2.使用AR方式 强类型语言存在的方式

    3.使用自动收集表单添加 :只能用POST方式,提交数据
    一个操作方法实现两个逻辑:
    A显示页面
    B得到数据 添加到数据库
    if(empty($_POST))
    {
    $this->show();
    }
    else
    {
    $n=D("Nation");
    $n->create(); //自动收集表单
    $r=$n->add(); add()会有返回值

    if($r)
    {
    success 参数 1给提示,2然后跳转到哪个方法,3跳转时间
    $this->success("跳转成功","add");
    }
    else
    {
    $this->error("跳转失败"); error失败自动跳回本方法
    !!需修改 有版本问题
    }
    }

    HTML页面: 表单的name属性 要与数据库字段 大小写与内容 相同保持一致,否则无法使用自动收集表单;

    如果数据库中没有该字段,表单中多出来添加数据的也不会生效;


    修改数据:实现两个逻辑1显示页面 2修改页面
    function update()
    {
    传默认数据:
    $db=D("表名"); 连接数据库,单表
    $arr1=$db->find($_GET["自定义名"]); get方式接收主键

    if(empty($_POST))
    {
    $this->assign("arr1",$arr1);
    }
    else
    {
    $db->create();
    $r=$db->save();
    if($r)
    {
    $this->success("修改OK",跳到哪个方法,几秒);
    }
    else
    {
    $this->error("修改失败");
    }
    }
    }


    删除 手动写code
    function del()
    {
    $n=D("Nation");
    $n->delete("n010,n016");
    }

    删除 传入code
    function del($code)
    {
    $n=D("Nation");
    $n->delete($code);
    }

    原生sql语句==>

    function yuansheng()
    {
    $n=D("Nation");
    $sql="delete from nation "
    $n->execute($sql);增删查用execute();
    查询用query();
    }

  • 相关阅读:
    September 29th 2017 Week 39th Friday
    September 28th 2017 Week 39th Thursday
    September 27th 2017 Week 39th Wednesday
    September 26th 2017 Week 39th Tuesday
    September 25th 2017 Week 39th Monday
    September 24th 2017 Week 39th Sunday
    angular2 学习笔记 ( Form 表单 )
    angular2 学习笔记 ( Component 组件)
    angular2 学习笔记 ( Http 请求)
    angular2 学习笔记 ( Router 路由 )
  • 原文地址:https://www.cnblogs.com/yuyu99/p/6903342.html
Copyright © 2011-2022 走看看