更新时间:2023-12-04 11:26:46
是的. select()
仅用于定义所需的列. get()
用于实际获取结果(>执行查询),它还允许您指定列.
Yes there is a difference. select()
is only for defining which columns you want. get()
is for actually getting the result (> executing the query) and it also allows you to specify columns.
DB::table('foo')->select(array('bar'));
将不执行.您仍然需要get()
DB::table('foo')->select(array('bar'))->get();
现在您只收到bar
列的结果.
可以通过这种方式完成同样的操作:
Now you receive a result with only the bar
column.
The same can be done this way:
DB::table('foo')->get(array('bar'));
所以单独按语法 get()
更快(意味着更短),而就性能而言,您不会注意到任何区别.
So syntax-wise get()
alone is faster (meaning shorter) while performance wise you won't notice any difference.
另一个小区别:通过select()
,您可以使用列表语法
Another little difference: with select()
you can use the list syntax
select('foo', 'bar', 'etc', 'whatever')
,并且使用get()
,您必须使用数组
and with get()
you have to use an array
get(array('foo', 'bar', 'etc', 'whatever'))