"Home/Model"文件夹剪切到Application文件夹下,HomeAdmin共同使用。

 

第一种实例化模型的方法

ThinkPHP3创建Model模型--对表的操作

第二种实例化模型的方法

ThinkPHP3创建Model模型--对表的操作

第三种实例化模型的方法

ThinkPHP3创建Model模型--对表的操作

tp3.2以后,M()和D()是一样的,在3.2之前版本中

M()类似于是  new Model();

D('goods')  类似于 new GoodsModel():

提示:我们可以看到goods表的信息,在GoodsModel中没有写代码,所有的业务逻辑都是Model类来实现的。

对表的操作

增加:M('表名')->add($data);

Insert into 表()  values(),()

删除:M('表名')->delete($id);

Delete from where

更新:M('表名')->save($data);

Update set 字段=值,字段=where

查询:M('表名')->select();

Select * from 表  where  group by  having  order by  limit

普通查询(显示所有的商品)

1GoodsController中的代码如下:

ThinkPHP3创建Model模型--对表的操作

2、在模板中循环取出goods/showlist.html

ThinkPHP3创建Model模型--对表的操作

3、获取一条记录

ThinkPHP3创建Model模型--对表的操作

条件查询

ThinkPHP3创建Model模型--对表的操作

ThinkPHP3创建Model模型--对表的操作

havingwhere的区别

区别一:

where后面跟的字段必须在数据表中有

having后面跟的字段必须在数据集中有

区别二:

select * from 表  where 条件  group by 分组  having 条件

动态查询

getby+字段名

ThinkPHP3创建Model模型--对表的操作

聚合函数

ThinkPHP3创建Model模型--对表的操作

数据添加

1、通过关联数组的方法添加

ThinkPHP3创建Model模型--对表的操作

2、通过ARactive  record)方式来添加

ThinkPHP3创建Model模型--对表的操作

数据修改

1、通过关联数组的方法

ThinkPHP3创建Model模型--对表的操作

 

 2、通过ARactive  record)方式

ThinkPHP3创建Model模型--对表的操作

数据删除

ThinkPHP3创建Model模型--对表的操作

直接执行SQL语句

ThinkPHP3创建Model模型--对表的操作

修改模板的链接

showlist.html

ThinkPHP3创建Model模型--对表的操作

add.html

ThinkPHP3创建Model模型--对表的操作

 

相关文章:

  • 2022-02-08
  • 2021-09-12
  • 2021-08-28
  • 2022-12-23
  • 2021-09-01
  • 2022-12-23
  • 2022-01-21
  • 2021-10-17
猜你喜欢
  • 2022-12-23
  • 2021-10-23
  • 2021-09-20
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
相关资源
相似解决方案