string(1) "9" ["bank_type"] => string(1) "1" ["bank_operator_id"] => string(1">
当前位置:Gxlcms > PHP教程 > Thinkphpwhere()方法的查找数据优化

Thinkphpwhere()方法的查找数据优化

时间:2021-07-01 10:21:17 帮助过:5人阅读

第一种方式

$bank = array(12) {
  ["bank_id"] => string(1) "9"
  ["bank_type"] => string(1) "1"
  ["bank_operator_id"] => string(1) "2"
  ["bank_operator_name"] => string(9) "唐新朋"
  ["bank_operator_type"] => string(1) "3"
  ["bank_accept_id"] => string(1) "1"
  ["bank_accept_name"] => string(9) "汪昌宁"
  ["bank_accept_type"] => string(1) "1"
  ["bank_sum"] => string(5) "50000"
  ["bank_mark"] => string(3) "500"
  ["bank_confirm"] => string(1) "0"
  ["bank_create_time"] => string(10) "1467113725"
}

$m->where($bank)->setField('bank_confirm','1');

第二种方式

$bank = array(12) {
  ["bank_id"] => string(1) "9"
  ["bank_type"] => string(1) "1"
  ["bank_operator_id"] => string(1) "2"
  ["bank_operator_name"] => string(9) "唐新朋"
  ["bank_operator_type"] => string(1) "3"
  ["bank_accept_id"] => string(1) "1"
  ["bank_accept_name"] => string(9) "汪昌宁"
  ["bank_accept_type"] => string(1) "1"
  ["bank_sum"] => string(5) "50000"
  ["bank_mark"] => string(3) "500"
  ["bank_confirm"] => string(1) "0"
  ["bank_create_time"] => string(10) "1467113725"
}

$condition['bank_id'] = $bank["bank_id"];
$m->where($condition)->setField('bank_confirm','1');

这两种方法都可以实现我想要的操作但是
第一种方法是否会对服务器或数据库造成压力

第二种是可以多写这一行代码

$condition['bank_id'] = $bank["bank_id"];

纠结中(⊙﹏⊙)

回复内容:

第一种方式

$bank = array(12) {
  ["bank_id"] => string(1) "9"
  ["bank_type"] => string(1) "1"
  ["bank_operator_id"] => string(1) "2"
  ["bank_operator_name"] => string(9) "唐新朋"
  ["bank_operator_type"] => string(1) "3"
  ["bank_accept_id"] => string(1) "1"
  ["bank_accept_name"] => string(9) "汪昌宁"
  ["bank_accept_type"] => string(1) "1"
  ["bank_sum"] => string(5) "50000"
  ["bank_mark"] => string(3) "500"
  ["bank_confirm"] => string(1) "0"
  ["bank_create_time"] => string(10) "1467113725"
}

$m->where($bank)->setField('bank_confirm','1');

第二种方式

$bank = array(12) {
  ["bank_id"] => string(1) "9"
  ["bank_type"] => string(1) "1"
  ["bank_operator_id"] => string(1) "2"
  ["bank_operator_name"] => string(9) "唐新朋"
  ["bank_operator_type"] => string(1) "3"
  ["bank_accept_id"] => string(1) "1"
  ["bank_accept_name"] => string(9) "汪昌宁"
  ["bank_accept_type"] => string(1) "1"
  ["bank_sum"] => string(5) "50000"
  ["bank_mark"] => string(3) "500"
  ["bank_confirm"] => string(1) "0"
  ["bank_create_time"] => string(10) "1467113725"
}

$condition['bank_id'] = $bank["bank_id"];
$m->where($condition)->setField('bank_confirm','1');

这两种方法都可以实现我想要的操作但是
第一种方法是否会对服务器或数据库造成压力

第二种是可以多写这一行代码

$condition['bank_id'] = $bank["bank_id"];

纠结中(⊙﹏⊙)

谢谢邀请。不知道你查询中的bank_id是不是唯一的,如果是唯一的第二种条件就足够了。虽然你第一种条件很多查询起来精确度也高,我看都是string类型,如果都是有索引还好,如果有的没有索引,一个条件足够的话我建议还是第二种。

谢邀,bank_id不出意外必然是唯一键或者主键,所以肯定
$m->where(array('bank_id' => $bank['bank_id']))->setField('bank_confirm','1');

楼上已经正确回答了你的问题,bank_id是唯一键则单条件查询

理论上查询条件越多,过滤数据越多,查询越快。但有一个主键或者索引字段即可,加个limit=1,效率就足够好了。

人气教程排行