• tp3.1(3)


    1、数据库的链接

     /*
        数据库配置
        */
        'DB_TYPE'=>'mysql',//数据类型
        'DB_HOST'=>'localhost',//数据服务器地址
        'DB_NAME'=>'thinkcmf',//数据库名
        'DB_USER'=>'root',//数据库用户名
        'DB_PWD'=>'',//数据用户名密码
        'DB_PORT'=>'3306',//数据库端口
        'DB_PREFIX'=>'cmf_',//数据库表前缀
        /*开启主从读写分离
        'DB_RW_SEPARATE'=>true,
        多个主数据库服务器
        'DB_MASTER_NUM'=>'2',

    2、添加数据

    M('Study')->add()

    M('Study')->addAll()

    3、查找数据

    1)使用字符串进行查询

    $date=M('Study')->where("id=1")->select();
    dump($date);

    2)是用数组的方式进行查询
    $where['id']=1;
    //$data=M('Study')->where($where)->select();
    dump($data);

    3)多个数据查找
    $where['xm']="张三";
    $where['id']=2;
    $where['_logic']="and/or";默认为and
    $date=M('Study')->where($where)->select();

    4)表达式的查询(eq neq egt gt lt elt between in like notbetween notin)
    $where['字段名']=array(表达式,查询条件);
    $where['id']=array('gt',2);
    $where['id']=array('between','1,5');
    $where['id']=array('not in','1,6');
    $where['xm']=array('like','%3');
    $where['xm']=array('like',array("王五%","%3"));

    5)区间查询
    $where['id']=array(array('gt',1),array('lt',5),'or');
    $this->display();
    6)、//混合使用
    $where['id']=array('gt',10);
    $where['_string']="xm='王五1112'";

     $date=M('Study')->where($where)->select();
    dump($date);

    7)统计用法

      count:统计数量

      max:最大值(必须传入字段名)

      min:最小值(必须传入字段名)

      avg:平均值(必须传入字段名)

      sum:总和(必须传入字段名)

    //$date=M('Study')->count();
    //$date=M('Study')->max('id');
    //$date=M('Study')->min('id');
    //$date=M('Study')->avg('id');

    3、数据的更新

    $where['id']=1;

    $update['xm']="李四";

    $data=M('Study')->where($where)->save($update);

    dump($data);

     4、数据的删除

    1)M(‘Study’)->delete(3);delete (主键)

    2)$where['id']=1;

    echo M('Study')->where($where)->delete();

  • 相关阅读:
    WCF 第十二章 对等网 实现一个自定义对等网解析器
    WCF 第十二章 对等网 System.Net.PeerToPeer.Collaboration
    WCF 第十二章 对等网 使用Windows Vista 来进行合作
    WCF 第十二章 对等网 使用PNRP解决对等网络问题
    WCF 第十二章 对等网 点对点应用程序
    WCF 第十二章 对等网 限制一条消息的跳数
    WCF 第十二章 对等网 创建P2P应用程序
    C#解析HTML
    C#中的DLL注入
    VC简单实现淡入淡出效果
  • 原文地址:https://www.cnblogs.com/yanran/p/5121880.html
Copyright © 2020-2023  润新知