【问题标题】:Google BigQuery Reading Rows into an arrayGoogle BigQuery 将行读入数组
【发布时间】:2016-09-28 07:32:37
【问题描述】:

当我尝试从 Google BigQuery 中的表中提取的数据中将行读取到数组中时,它只会将第一行读取到数组中。

我在其他代码中也是这样做的,不知道为什么没有读取所有行。

<?php
    function top10($chart){
        $client = new Google_Client();
        $client->useApplicationDefaultCredentials();
        $client->addScope(Google_Service_Bigquery::BIGQUERY);
        $bigquery = new Google_Service_Bigquery($client);
        $projectId = 'projectID';

        $request = new Google_Service_Bigquery_QueryRequest();

        $query = "SELECT First_Name, Last_Name, G FROM [" . $chart. "] ORDER BY G DESC LIMIT 10";

        $request->setQuery($query);

        $response = $bigquery->jobs->query($projectId, $request);
        $rows = $response->getRows();

        $ii = 0;
        $i = 0;
        foreach ($rows as $row)
        {
            foreach ($row['f'] as $field)
            {
                $Info[$i][$ii] = $field['v'];
                $ii++;
            }
            $i++;
        }
    }
?>

【问题讨论】:

    标签: php google-app-engine multidimensional-array google-bigquery


    【解决方案1】:

    你需要使用这样的东西:

     $rows = $queryResults->rows();
            foreach ($rows as $row) {
                printf('--- Row %s ---' . PHP_EOL, ++$i);
                foreach ($row as $column => $value) {
                    printf('%s: %s' . PHP_EOL, $column, $value);
                }
            }
    

    完整示例here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-14
      • 2016-04-25
      • 1970-01-01
      • 1970-01-01
      • 2021-12-07
      • 2017-09-05
      • 2022-12-10
      • 2019-05-18
      相关资源
      最近更新 更多