java小白学习tp5学习过程随笔一crud
其他
2019-01-27 16:41:48
阅读次数: 0
初来乍到,第一次写博文,可能写的非常的烂,各位大佬多多包涵。
tp5.1框架,配置啥的都不懂,平时只写写crud。。。在这里写写随笔方便以后随时看。
1.1查询
$res =Db :: table("a","b") //table 括号里放 表名 a 、b 各表示表名
->where ("a.id = b.id") //这里的where 直接可表示连表的on 一个where直接连表
->where ("a.id = 6") //这里的where类似sql里的where 和 and 紧跟的条件
->limit(0,10) //分页
->field ("a.*,b.*") // 查询的列
->order("a.time","desc") // 排序
->find() //查询1条数据
->slect() //查询集合
select() 、find() 二者不可一起用,根据业务需求选择使用
----------------------------------------------------------------------------------------------------------------
1.2 新增
$data = [
"id" => 1,
"name" => "xbq"
];
$insert = Db :: table("a")->insertGetId($data) // insertGetId()、返回id。
$insert = Db :: table("a")->insert($data) // insert 普通新增。
根据业务来选择使用
----------------------------------------------------------------------------------------------------------------
1.3修改
Db :: table("a")
->where("id",1)
-> update([
'name' => "xbq"
])
----------------------------------------------------------------------------------------------------------------
1.4 删除
Db :: table("a")
->where("id",1)
->delete();
----------------------------------------------------------------------------------------------------------------
以上只是一些基础的tp5框架的crud。
转载自blog.csdn.net/weixin_41327271/article/details/85066595