mysql_xdevapi\CollectionFind
PHP Manual

CollectionFind::fields

(No version information available, might only be in Git)

CollectionFind::fieldsSet document field filter

说明

public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::fields ( string $projection )

This is the equivalent of the SQL projection, which allows to select which columns the query shall return.

参数

projection

Can either be a single string or an array of string, those strings are identifying the columns that have to be returned for each document that match the search condition.

返回值

A CollectionFind object that can be used for further processing

范例

Example #1 mysql_xdevapi\CollectionFind::fields() example

<?php

//Assuming $coll is a valid collection object

/*
   The following find call will search for all the documents
   with a 'job' like 'tassinaro' and will return only the column
   'age' from each document
*/
$res $coll->find('job like \'tassinaro\'')->fields('age')->execute();

//Example which make use of the COUNT function
    
$res $coll->find()->fields(['COUNT(name) as cn''MAX(age) as ma''job as j'])->execute();
    

?>

mysql_xdevapi\CollectionFind
PHP Manual