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()->..忽略表前缀
//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(); 返回影响行数
If you want The condition for deletion is the primary key, you don’t need to write 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('id','between','1,5')->buildSql(); id在1-5之间的,包括1和5
Db::name()->where(['id'=>1])->buildSql(); Db::name()->where(['id'=>['in',[1,2,3,4]]])->buildSql();
[The two conditions are related by and 】
Db::name()->where( ['id'=>1], ['name'=>'kaluo'] )->buildSql();
EXP is a conditional expression
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('name','buld')->buildSql();
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
Chain operation
Db::table()->where('id','>',10)->select();查询的表中的所有的字段
[field method]
Db::table()->where('id','>',10)->field("name,id")->select();查询表中的name,id字段
[order method]
Db::table()->where('id','>',10)->field("name,id")->order("id DESC")->limit(3,5)->select();查询表中的name,id字段,倒叙排序,从第三条开始取,取5条
[page method][page(2, 5) Starting from the second page, display five items】
Db::table()->where('id','>',10)->field("name,id")->order("id DESC")->page(3,5)->select();查询表中的name,id字段,倒叙排序,从第三页开始取,取5条
【group】
Db::table()->where('id','>',10)->field("name,id")->group("`group`")->select();查询表中的name,id字段,以group分组
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!