Blogger Information
Blog 43
fans 4
comment 0
visits 19257
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
thinkphp安装配置/数据库的增删改查
汇享科技
Original
383 people have browsed it

1. 安装thinkphp

使用composer进行安装composer create-project topthink/think tp

2. 数据库配置链接

找到config目录下的database.php文件进行配置

51608-cg9pxbn6b4.png

3. 数据库操作 增删改查

  • 增加数据 insert

02642-arhkn43s6ch.png

  • 增加数据 insertAll

96586-8vydecg8q46.png

  • insertGetId 返回添加数据的自增主键

32888-a8uvx4lslh8.png

  • 删除数据 delete

21422-tgupmteymtj.png

  • 软删除 useSoftDelete

51592-v5okw0stfho.png

  • 修改 update

51536-xed3e37u43e.png

  • 查询 select

53898-t6sf447rio.png

代码

  1. //1.1 增 insert 返回添加成功的条数
  2. // $data = [
  3. // 'name' => '小编',
  4. // 'email' => 'xiaobian@qq.com',
  5. // 'password' => sha1(123456),
  6. // 'reg_time' => time()
  7. // ];
  8. // $res = Db::table('user')->insert($data);
  9. // print_r($res);
  10. //1.2增 insertAll 返回添加成功的条数
  11. // $data = [
  12. // [
  13. // 'name' => '小编1',
  14. // 'email' => 'xiaobian0@qq.com',
  15. // 'password' => sha1(123456),
  16. // 'reg_time' => time()
  17. // ],
  18. // [
  19. // 'name' => '小编2',
  20. // 'email' => 'xiaobian2@qq.com',
  21. // 'password' => sha1(123456),
  22. // 'reg_time' => time()
  23. // ],
  24. // [
  25. // 'name' => '小编3',
  26. // 'email' => 'xiaobian3@qq.com',
  27. // 'password' => sha1(123456),
  28. // 'reg_time' => time()
  29. // ]
  30. // ];
  31. // $res = Db::table('user')->insertAll($data);
  32. // print_r($res);
  33. // 1.3 insertGetId 返回主键值
  34. // $data = [
  35. // 'name' => '小编4',
  36. // 'email' => 'xiaobian4@qq.com',
  37. // 'password' => sha1(123456),
  38. // 'reg_time' => time()
  39. // ];
  40. // $res = Db::table('user')->insertGetId($data);
  41. // print_r($res);
  42. //2.1 删除 delete 返回删除数据的条数 没删除则返回0
  43. // $res = Db::table('user')->where('id', '11')->delete();
  44. // echo '删除了' . $res . '条数据';
  45. //2.2 软删除 useSoftDelete 将某一个字段的值进行更改
  46. // $res = Db::table('user')->where('id', 10)->useSoftDelete('password', 2)->delete();
  47. // echo '删除了' . $res . '条数据';
  48. // 3.1 修改update 返回受到影响的条数 没有返回0
  49. // $data = [
  50. // 'password' => sha1(123456789),
  51. // ];
  52. // $res = Db::table('user')->where('id', 1)->update($data);
  53. // echo '修改了' . $res . '条数据';
  54. // 查询 select
  55. // $res = Db::table('user')->select();
  56. // printf("<pre>%s</pre>", print_r($res, true));
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!