Google\Cloud\BigQuery\QueryResults::rows PHP Method

rows() public method

Refer to the table below for a guide on how BigQuery types are mapped as they come back from the API. | **PHP Type** | **BigQuery Data Type** | |--------------------------------------------|--------------------------------------| | \DateTimeInterface | DATETIME | | {@see \Google\Cloud\BigQuery\Bytes} | BYTES | | {@see \Google\Cloud\BigQuery\Date} | DATE | | {@see \Google\Cloud\Int64} | INTEGER | | {@see \Google\Cloud\BigQuery\Time} | TIME | | {@see \Google\Cloud\BigQuery\Timestamp} | TIMESTAMP | | Associative Array | RECORD | | Non-Associative Array | RECORD (Repeated) | | float | FLOAT | | int | INTEGER | | string | STRING | | bool | BOOLEAN | Example: $isComplete = $queryResults->isComplete(); if ($isComplete) { $rows = $queryResults->rows(); foreach ($rows as $row) { echo $row['name'] . PHP_EOL; } }
public rows ( array $options = [] ) : array
$options array [optional] Configuration options.
return array
    public function rows(array $options = [])
    {
        if (!$this->isComplete()) {
            throw new GoogleException('The query has not completed yet.');
        }
        if (!isset($this->info['rows'])) {
            return;
        }
        $schema = $this->info['schema']['fields'];
        while (true) {
            $options['pageToken'] = isset($this->info['pageToken']) ? $this->info['pageToken'] : null;
            foreach ($this->info['rows'] as $row) {
                $mergedRow = [];
                if ($row === null) {
                    continue;
                }
                if (!array_key_exists('f', $row)) {
                    throw new GoogleException('Bad response - missing key "f" for a row.');
                }
                foreach ($row['f'] as $key => $value) {
                    $fieldSchema = $schema[$key];
                    $mergedRow[$fieldSchema['name']] = $this->mapper->fromBigQuery($value, $fieldSchema);
                }
                (yield $mergedRow);
            }
            if (!$options['pageToken']) {
                return;
            }
            $this->info = $this->connection->getQueryResults($options + $this->identity);
        }
    }