Thinkphp中field和getField

简介:

在数据库查询操作中field和getField方法是使用最频繁的。可是两者是有一定差别的。在这里记录下。

field方法是用于定义要查询的字段(支持字段排除)。


getField方法获取数据表中的某个列的多个或者单个数据。

比方我要想选择用户表中指定行的id和token两项json数据,我期望的数据是这种

{
id: "9"
token: "d56ccc55e1d65e01a94c27c0442f3eb3"
}

增加用getField方法,语句这样写:$user->where("phone=$getPostPhone")->getField('id,token');

可是它返回的结果让我非常尴尬

9: "d56ccc55e1d65e01a94c27c0442f3eb3"
假设用field,语句这样写:$user->where("phone=$getPostPhone")->field('id,token')->find();

返回的结果是期望的结果。

id: "9"
token: "d56ccc55e1d65e01a94c27c0442f3eb3"








本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5072840.html,如需转载请自行联系原作者


相关文章
|
SQL 算法
【hacker的错误集】html5lib使用报错Couldn‘t find a tree builder with the features you requested: html5lib
分析得出:bs4的特征没有找到:找不到具有您请求功能的树生成器:html5lib。您需要安装解析器库吗?
322 0
【hacker的错误集】html5lib使用报错Couldn‘t find a tree builder with the features you requested: html5lib
|
9月前
|
PHP
php模版引擎smarty出现Undefined index的解决方案
php模版引擎smarty出现Undefined index的解决方案
66 0
|
测试技术 PHP
PHP:laravel自定义Model报错:$table must not be defined/$table must be string
PHP:laravel自定义Model报错:$table must not be defined/$table must be string
102 0
|
存储 自然语言处理 索引
lucene中Field.Index,Field.Store的一些设置
lucene在doc.add(new Field("content",curArt.getContent(),Field.Store.NO,Field.Index.TOKENIZED));
111 0
|
PHP
【laravel】模型一对一Trying to get property 'price' of non-object
【laravel】模型一对一Trying to get property 'price' of non-object
113 0
【laravel】模型一对一Trying to get property 'price' of non-object
SAP Cloud for Customer 2102版本如何使用Key User Tool创建扩展字段 - extension field
SAP Cloud for Customer 2102版本如何使用Key User Tool创建扩展字段 - extension field
SAP Cloud for Customer 2102版本如何使用Key User Tool创建扩展字段 - extension field
How to add extension field to report
How to add extension field to report
106 0