4.查询要的字段

1.使用field函数查询要的字段
字段名用逗号分隔

$fields = "wx_name,wx_gender";
$res = Db::name('member')->field($fields)->select();

查询结果如下:

array(3) {
  [0] => array(2) {
    ["wx_name"] => string(6) "peiwei"
    ["wx_gender"] => int(1)
  }
  [1] => array(2) {
    ["wx_name"] => string(6) "jiawei"
    ["wx_gender"] => int(1)
  }
}

2.设置查询出来字段的别名

$fields = "wx_name as name,wx_gender";
$res = Db::name('member')->field($fields)->select();

查询结果如下:

array(3) {
  [0] => array(2) {
    ["name"] => string(6) "peiwei"
    ["wx_gender"] => int(1)
  }
  [1] => array(2) {
    ["name"] => string(6) "jiawei"
    ["wx_gender"] => int(1)
  }
}