博主信息
博文 43
粉丝 4
评论 0
访问量 28779
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
thinkphp高级数据查询/请求示例
汇享科技
原创
1285人浏览过

1. 高级数据查询

  1. where条件查询 符号查询 [<,>,<=,>=,<>]
  1. id大于2 id小于7
  2. $res = Db::table('user')->where('id', '>', 2)->where('id', '<', 7)->select();
  3. printf("<pre>%s</pre>", print_r($res, true));
  4. id=2
  5. $res = Db::table('user')->where('id', '=', 3)->select();
  6. printf("<pre>%s</pre>", print_r($res, true));
  1. 模糊查询
  1. $res = Db::table('user')->where('name', 'like', '%编%')->select();
  2. printf("<pre>%s</pre>", print_r($res, true));
  3. //模糊取反
  4. $res = Db::table('user')->where('name', 'notlike', '%编%')->select();
  5. printf("<pre>%s</pre>", print_r($res, true));
  1. 区间查询
  1. $res = Db::table('user')->where('id', 'between', '2,7')->select();
  2. printf("<pre>%s</pre>", print_r($res, true));
  3. //区间取反
  4. $res = Db::table('user')->where('id', 'not between', '2,7')->select();
  5. printf("<pre>%s</pre>", print_r($res, true));
  1. 返回值查询field 查询指定字段
  1. $res = Db::table('user')->field('id')->select();
  2. printf("<pre>%s</pre>", print_r($res, true));
  1. 排序 order DESC倒序 ASC正序
  1. $res = Db::table('user')->order('id', 'DESC')->select();
  2. printf("<pre>%s</pre>", print_r($res, true));
  1. 分页 limit 方法主要用于指定查询和操作的数量
  1. $res = Db::table('user')->limit(4, 10)->select();
  2. printf("<pre>%s</pre>", print_r($res, true));
  3. //page 专用分页查询
  4. $res = Db::table('user')->page(0, 5)->select();
  5. printf("<pre>%s</pre>", print_r($res, true));
  1. 聚合查询
  1. //count
  2. $res = Db::table('user')->count();
  3. echo $res;
  1. 多个数据库查询 在database.php配置好另一个数据库之后 使用connect()选择数据库进行查询默认是第一个数据库
  1. $res = Db::connect('lyb')->table('user_list')->select();
  2. printf("<pre>%s</pre>", print_r($res, true));

2.数据请求

  1. //数据请求
  2. // print_r(Request::get());
  3. // print_r(Request::post());

15220-7js5xm7oho.png

48040-pjx6wb0a6jj.png

批改老师:PHPzPHPz

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学