Home  >  Article  >  Backend Development  >  ThinkPHP5 CURL operation method for database

ThinkPHP5 CURL operation method for database

一个新手
一个新手Original
2017-10-23 09:17:332786browse

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

//Add data [Array]

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

//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字段每次自减

Delete

Db::name()->where()->delete(); 返回影响行数
如果要删除的条件是主键,可以不写where
Db::name()->delete(1); 删除id=1的记录

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
Db::name()->where([&#39;id&#39;=>1])->buildSql();
Db::name()->where([&#39;id&#39;=>[&#39;in&#39;,[1,2,3,4]]])->buildSql();

[The relationship between the two conditions is and]

Db::name()->where(
[&#39;id&#39;=>1],
[&#39;name&#39;=>&#39;kaluo&#39;]
)->buildSql();
EXP 是条件表达式
Db::name()->where("id","EXP"," not in (1,2,3)")->buildSql();

[The relationship between the two conditions is OR]

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

where() contains arrays, strings, and parameters

# Remarks [letters will be compiled into the following 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::
between
in

Chain operation

Db::table()->where(&#39;id&#39;,&#39;>&#39;,10)->select();查询的表中的所有的字段
【field方法】Db::table()->where(&#39;id&#39;,&#39;>&#39;,10)->field("name,id")->select();查询表中的name,id字段
【order方法】Db::table()->where(&#39;id&#39;,&#39;>&#39;,10)->field("name,id")->order("id DESC")->limit(3,5)->select();查询表中的name,id字段,倒叙排序,从第三条开始取,取5条
【page方法】【page(2,5)从第二页开始,显示五条】Db::table()->where(&#39;id&#39;,&#39;>&#39;,10)->field("name,id")->order("id DESC")->page(3,5)->select();查询表中的name,id字段,倒叙排序,从第三页开始取,取5条
【group分组】Db::table()->where(&#39;id&#39;,&#39;>&#39;,10)->field("name,id")->group("`group`")->select();查询表中的name,id字段,以group分组

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

Statement:
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