Blogger Information
Blog 43
fans 4
comment 0
visits 19263
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
thinkphp高级数据查询/请求示例
汇享科技
Original
679 people have browsed it

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

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!