Blogger Information
Blog 50
fans 0
comment 0
visits 31522
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
tp6的框架的搭建
手机用户1580651468
Original
898 people have browsed it

tp6的框架的搭建

一、搭建ThinkPHP项目

一)利用composer工具安装

二)测试能否访问

二、配置数据库

在database里面配置

一、增删查改

一)、查询

1. 单条数据查询

  1. $user = Db::table('oyk_user')->find();

2、where条件

  1. $user =Db::table('oyk_user')->where('nickname','小编6')->find();

3、查询多条select多条数据查询出来的值是对象。

  1. $user = Db::table('oyk_user')->where('uid','>','6')->select();

4、value 查询某个值

  1. $user = Db::table('oyk_user')->where('uid','=','6')->value('nickname');

二)、添加

1、添加功能,先整理数据,一般是从前端发送过来

  1. $data = [
  2. 'nickname' => '小编7',
  3. 'phone' => '18822226666'
  4. ];
  5. $add = Db::table('oyk_user')->insert($data);

三)、修改

1、修改 update

  1. $data = [
  2. 'nickname' => '小编9',
  3. 'phone' => 18822228888
  4. ];
  5. $update = Db::table('oyk_user')->where('uid',16)->update($data);

2、如果修改一个单独的值,操作数据表会麻烦。

  1. 自增 inc ,自减 dec 用在访问日志上
  2. $update = Db::table('oyk_user')->where('uid',16)->inc('log_num',10)->update();

四)、删除 delete

1. 删除和修改,必须增加条件

  1. $delete = Db::table('oyk_user')->where('uid',16)->delete();

2.软删除,数据删除了,还存在数据表中。 就是把字段的值改变,改变成1个大家公认是删除的值

  1. useSoftDelete
  2. $delete = Db::table('oyk_user')->where('uid',15)->useSoftDelete('status',99)->delete();
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