【问题标题】:Using PHP with Google BigQuery将 PHP 与 Google BigQuery 结合使用
【发布时间】:2021-04-19 07:09:12
【问题描述】:

我是 Google Cloud Platform 的新手,出于学习目的,我使用 Zomato API 创建了一个简单的餐厅查找器,并将其托管在 Google Cloud Platform 上。

目前,我使用在 Google BigQuery 平台上在线找到的 CSV 文件创建了一个数据集,并运行了一些简单的查询,例如

SELECT restaurant_name FROM "restaurants" WHERE rating > 4.0

在平台本身上,结果以表格形式显示。

无论如何,我的问题是使用 PHP 对我在 BigQuery 上创建的数据集运行简单查询并将结果显示到托管在 Google Cloud Platform 上的我的网站上?

【问题讨论】:

  • 您的费率很低。对 SO 很重要,您必须使用已发布答案左侧、投票下方的勾号来标记已接受的答案。这将提高您的费率。通过访问此链接了解其工作原理:meta.stackoverflow.com/questions/5234/…

标签: php google-cloud-platform google-bigquery


【解决方案1】:

你会开始这样的事情

 composer require google/cloud-bigquery

一个代码示例是

require 'vendor/autoload.php';

use Google\Cloud\BigQuery\BigQueryClient;

$bigQuery = new BigQueryClient([
'keyFilePath' => '/path/to/keyfile.json'
]);

// Get an instance of a previously created table.
$dataset = $bigQuery->dataset('my_dataset');
$table = $dataset->table('my_table');

// Begin a job to import data from a CSV file into the table.
$loadJobConfig = $table->load(
    fopen('/data/my_data.csv', 'r')
);
$job = $table->runJob($loadJobConfig);

// Run a query and inspect the results.
$queryJobConfig = $bigQuery->query(
    'SELECT * FROM `my_project.my_dataset.my_table`'
);
$queryResults = $bigQuery->runQuery($queryJobConfig);

foreach ($queryResults as $row) {
    print_r($row);
}

更多示例:https://github.com/googleapis/google-cloud-php

【讨论】:

  • 如何在 Google App Engine 上使用 composer?有没有办法将它安装到 Google App Engine?
  • Composer 在 App Engine 上自动运行。您的供应商文件夹将比require '../vendor/autoload.php';高一级
猜你喜欢
  • 1970-01-01
  • 2011-10-30
  • 1970-01-01
  • 1970-01-01
  • 2019-02-24
  • 2021-10-05
  • 2021-04-15
  • 2021-01-01
  • 1970-01-01
相关资源
最近更新 更多