Db::table( ‘数据表名’ ) -> where( 查询条件 ) -> column( ‘字段列表’, ‘数组键名’ ) ;
Db::table('User')->where(['status'=>['>',0]])->column('id,name,tel','tel');
返回结果
[
'15698963256'=>[
'id'=>1,
'name'=>'小明',
'tel'=>'15698963256'
]
]
本文介绍了一种使用ThinkPHP5框架进行数据库查询的高级方法,通过Db类的table、where和column方法组合,实现对User表中特定字段的高效检索,并展示了如何设置查询条件和指定返回结果的键名。
Db::table( ‘数据表名’ ) -> where( 查询条件 ) -> column( ‘字段列表’, ‘数组键名’ ) ;
Db::table('User')->where(['status'=>['>',0]])->column('id,name,tel','tel');
返回结果
[
'15698963256'=>[
'id'=>1,
'name'=>'小明',
'tel'=>'15698963256'
]
]