Blogger Information
Blog 52
fans 1
comment 1
visits 38278
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
下载、安装、运行Thinkphp6
小丑0o鱼
Original
672 people have browsed it

ThinkPHP6.0 的环境要求如下:

1.
PHP >= 7.1.0
Thinkphp6 开始,必须通过 Composer 方式安装和更新

composer require topthink/think
2、安装view

composer require topthink/think-view
3、写出增删查改语句

查询

  1. select - 查询多条数据,结果返回对象,数据不存在,返回空对象
  2. find - 查询单条数据,结果返回一维数组,数据不存在,返回 null
  3. value - 查询某个字段的值,结果返回文本,数据不存在,返回 null
  4. column - 查询某一列的值,结果返回一维数组,数据不存在,返回空数组
  1. /**
  2. * 查询
  3. */
  4. public function select()
  5. {
  6. // 查询多条数据,结果返回对象,数据不存在,返回空对象
  7. $select = Db::name('boke')->select(1);
  8. var_dump($select);
  9. echo '<hr>';
  10. // 查询单条数据,结果返回一维数组,数据不存在,返回 null
  11. $find = Db::name('boke')->find(5);
  12. var_dump($find);
  13. echo '<hr>';
  14. // 查询某个字段的值,结果返回文本,数据不存在,返回 null
  15. $value = Db::name('boke')->value('title');
  16. var_dump($value);
  17. echo '<hr>';
  18. // 查询某一列的值,结果返回一维数组,数据不存在,返回空数组
  19. $column = Db::name('boke')->column('title');
  20. var_dump($column);
  21. echo "<hr>";
  22. }
  1. /**
  2. * 增加
  3. */
  4. public function create()
  5. {
  6. $data = [
  7. 'title'=>'在线考试系统实战【公益直播】',
  8. 'img'=>'https://img.php.cn/upload/course/000/000/001/60862c6ba99af257.png',
  9. 'content'=>'三天大型公益直播课《模仿驾校考试系统实战开发》,使用框架: bootstrap、jquery、ThinkPHP6.0',
  10. 'date'=>'2021-05-06',
  11. 'cat'=>'PHP'
  12. ];
  13. // 添加一条数据,成功返回条数
  14. $create = Db::name('boke')->insert($data);
  15. var_dump($create);
  16. echo "<hr>";
  17. // 添加一条数据,成功返回自增主键
  18. $getId = Db::name('boke')->insertGetId($data);
  19. var_dump($getId);
  20. echo "<hr>";
  21. // 添加多条数据,成功返回条数
  22. $data2 = [
  23. [
  24. 'title'=>'在线报名系统(移动端)实战【公益直播】',
  25. 'img'=>'https://img.php.cn/upload/course/000/000/001/6072932baeb4e177.png',
  26. 'content'=>'大型公益课,2021.4.12号晚上20:00开始,连续5晚,全程直播,一起开发一个中小学兴趣班报名系统!',
  27. 'date'=>'2021-04-23',
  28. 'cat'=>'PHP'
  29. ],
  30. [
  31. 'title'=>'Vue.js开发基础',
  32. 'img'=>'https://img.php.cn/upload/course/000/000/015/6077fb8677ac6448.png',
  33. 'content'=>'Vue.js是非常流行的一个前端开发框架,采用渐进式底层向上开发模式,使用了主流的MVVM设计框架。本课以Vue.js开发的核心理念与常用技术为背景,让您在最短的时间内理解并掌握Vue.js框架的核心知识,为进一步深造打下良好的基础。',
  34. 'date'=>'2021-04-28',
  35. 'cat'=>'JS'
  36. ]
  37. ];
  38. $insertAll = Db::name('boke')->insertAll($data2);
  39. var_dump($insertAll);
  40. echo "<hr>";
  41. }
  1. /**
  2. * 修改
  3. */
  4. public function update()
  5. {
  6. // 修改数据,成功返回条数
  7. $update = Db::name('boke')->where('id', 1)->update(['title'=>'在线报名系统(移动端)实战【公益直播】']);
  8. var_dump($update);
  9. echo "<hr>";
  10. // 自增字段的值
  11. $inc = Db::name('boke')->where('id',1)->inc('num',2)->update();
  12. var_dump($inc);
  13. echo "<hr>";
  14. // 自减字段的值
  15. $dec = Db::name('boke')->where('id',1)->dec('num', 2)->update();
  16. var_dump($dec);
  17. echo "<hr>";
  1. public function delete()
  2. {
  3. // 删除数据,成功返回条数,没有删除返回 0
  4. $delete = Db::name('boke')->delete(17);
  5. var_dump($delete);
  6. }
Correction status:Uncorrected

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!