TP5 implementation code sharing for CURL operation on database

黄舟
Release: 2023-03-16 18:00:02
Original
2725 people have browsed it

TP5 implementation code sharing of CURL operation on database

Db::query();Db::execute();
Db::table()->select();所有数据,二维数组,结果不存在时返回空数组
Db::table->find();一条数据,一维数组,结果不存在时返回NULL
Db::table->value();一条数据,结果不存在时返回空
Db::table->column();返回一个一维数组;如果有第二个参数,返回以第二个数作为标识的数组,结果不存在时,返回NULL
Db::table()->...表名加表前缀
Db::name()->..忽略表前缀
Copy after login


//Add data [array]

Db::name()->insert();返回影响行数
Db::name()->insertGetId(); 获取最后的新增id
Db::name()->insertAll();插入全部数据
Copy after login

//Update database [Array]

Db::name()->where()->update(); 返回影响行数
Db::name()->where()->setField('name','小米');更新数据的某一个字段 返回影响行数
Db:name()->where->setInc('num'); num字段名每次自增1
Db:name()->where->setInc('num',5); num字段名每次自增5
Db::name()->where()->setDec('num'); num字段每次自减
Copy after login


Delete

Db::name()->where()->delete(); 返回影响行数
Copy after login


If you want The condition for deletion is the primary key, you don’t need to write where

Db::name()->delete(1); 删除id=1的记录
Copy after login


Conditional constructor

Db::name()->where()->buildSql();返回sql语句
Db::name()->where("id=1")->buildSql();传递条件
Db::name()->where("id",1)->buildSql();传递字段名,和想使用的值
Db::name()->where("id","<>",1)->buildSql(); 字段名,表达式,想要判断的值
Db::name()->where(&#39;id&#39;,&#39;between&#39;,&#39;1,5&#39;)->buildSql(); id在1-5之间的,包括1和5
Copy after login
Db::name()->where([&#39;id&#39;=>1])->buildSql();
Db::name()->where([&#39;id&#39;=>[&#39;in&#39;,[1,2,3,4]]])->buildSql();
Copy after login

[The two conditions are related by and 】

Db::name()->where(
[&#39;id&#39;=>1],
[&#39;name&#39;=>&#39;kaluo&#39;]
)->buildSql();
Copy after login


EXP is a conditional expression

Db::name()->where("id","EXP"," not in (1,2,3)")->buildSql();
Copy after login

【The relationship between the two conditions is or】

Db::name()->where("id","in","1,2,3")->whereOr(&#39;name&#39;,&#39;buld&#39;)->buildSql();
Copy after login

where( ) contains an array, a string, and a parameter

# Remarks [letters will be compiled into subsequent symbols, etc.] [conditions are not case-sensitive]
# EQ =
# NEQ < >
# LT <
# ELT <=
# GT >
# EGT >=
# BETWEEN BETWEEN * AND *
# NOTBETWEEN NOT BETWEEN * AND *
# IN IN(*,*)
# NOTIN NO TIN(*,*)

Expression: :

betweenin
Copy after login

Chain operation

Db::table()->where(&#39;id&#39;,&#39;>&#39;,10)->select();查询的表中的所有的字段
Copy after login

[field method]

Db::table()->where(&#39;id&#39;,&#39;>&#39;,10)->field("name,id")->select();查询表中的name,id字段
Copy after login

[order method]

Db::table()->where(&#39;id&#39;,&#39;>&#39;,10)->field("name,id")->order("id DESC")->limit(3,5)->select();查询表中的name,id字段,倒叙排序,从第三条开始取,取5条
Copy after login

[page method][page(2, 5) Starting from the second page, display five items】

Db::table()->where(&#39;id&#39;,&#39;>&#39;,10)->field("name,id")->order("id DESC")->page(3,5)->select();查询表中的name,id字段,倒叙排序,从第三页开始取,取5条
Copy after login

【group】

Db::table()->where(&#39;id&#39;,&#39;>&#39;,10)->field("name,id")->group("`group`")->select();查询表中的name,id字段,以group分组
Copy after login

The above is the detailed content of TP5 implementation code sharing for CURL operation on database. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template