我想在PHP腳本中使用INSERT命令,在數據庫中插入大量的記錄,因爲它會更容易訪問,但https://developers.google.com/bigquery/docs/query-reference,這不表明可以同時在PHP查詢中使用一樣, $ quert-> setQuery INSERT命令(「INSERT INTO ... ...值」),在查詢表的BigQuery的Web控制檯嘗試過這一點,但它不似乎無法正常工作,有沒有辦法使用setQuery()和其他命令來插入數據?INSERT BigQuery中的查詢部分,使用谷歌的API的PHP客戶端
0
A
回答
1
的BigQuery不支持INSERT命令。您需要創建一個加載作業。有關更多信息,請參見https://developers.google.com/bigquery/docs/import#localimport。
1
除了喬丹的回答,這裏有一段代碼,應該讓您開始使用Google BigQuery API和Google API PHP client library以編程方式將自己的數據加載到BigQuery中。請注意,這段代碼只是簡單地將加載作業的原始API響應(包括作業ID)吐出到屏幕上 - 您必須添加您自己的輪詢邏輯來檢查加載作業狀態。
(我們將增加約很快加載自己的數據,以及更多的PHP樣本附加文檔)。
<?php
require_once "google-api-php-client/src/Google_Client.php";
require_once "google-api-php-client/src/contrib/Google_BigqueryService.php";
session_start();
$client = new Google_Client();
// Visit https://code.google.com/apis/console to generate your
// oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri.
$client->setScopes(array('https://www.googleapis.com/auth/bigquery'));
$client->setClientId('XXXXXXXXX.apps.googleusercontent.com');
$client->setClientSecret('XXXXXXXXX');
$client->setRedirectUri('http://YOURAPPLICATION/index.php');
// Instantiate a new BigQuery Client
$bigqueryService = new Google_BigqueryService($client);
if (isset($_GET['code'])) {
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
?>
<!doctype html>
<html>
<head>
<title>BigQuery API Sample</title>
</head>
<body>
<div id='container'>
<div id='top'><h1>BigQuery API Sample</h1></div>
<div id='main'>
<?php
if (isset($_GET['logout'])) {
unset($_SESSION['token']);
}
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if ($client->getAccessToken()) {
// Your project number, from the developers.google.com/console project you created
// when signing up for BigQuery
$project_number = 'XXXXXXXXXXXXXX';
// Information about the destination table
$destination_table = new Google_TableReference();
$destination_table->setProjectId($project_number);
$destination_table->setDatasetId('php_test');
$destination_table->setTableId('my_new_table');
// Information about the schema for your new table
$schema_fields = array();
$schema_fields[0] = new Google_TableFieldSchema();
$schema_fields[0]->setName('first');
$schema_fields[0]->setType('string');
$schema_fields[1] = new Google_TableFieldSchema();
$schema_fields[1]->setName('last');
$schema_fields[1]->setType('string');
$destination_table_schema = new Google_TableSchema();
$destination_table_schema->setFields($schema_fields);
// Set the load configuration, including source file(s) and schema
$load_configuration = new Google_JobConfigurationLoad();
$load_configuration->setSourceUris(array('gs://YOUR_GOOGLE_CLOUD_STORAGE_BUCKET/file.csv'));
$load_configuration->setDestinationTable($destination_table);
$load_configuration->setSchema($destination_table_schema);
$job_configuration = new Google_JobConfiguration();
$job_configuration->setLoad($load_configuration);
$load_job = new Google_Job();
$load_job->setKind('load');
$load_job->setConfiguration($job_configuration);
$jobs = $bigqueryService->jobs;
$response = $jobs->insert($project_number, $load_job);
echo '<pre>';
print_r($response);
echo '</pre>';
$_SESSION['token'] = $client->getAccessToken();
} else {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Authorize Access to the BigQuery API</a>";
}
?>
</div>
</div>
</body>
</html>
相關問題
- 1. 的遊離鹼PHP谷歌API(谷歌API的PHP客戶端)
- 2. 使用谷歌API PHP客戶端庫
- 3. 谷歌的BigQuery API(Python客戶端庫)>查詢數據(異步)
- 4. 在谷歌BigQuery中,如何使用谷歌Python客戶端的JavaScript UDF
- 5. 如何使用谷歌的API的PHP客戶端
- 6. (400)使用許可庫谷歌的API的PHP客戶端
- 7. 使用谷歌的API的PHP客戶端
- 8. 無法使用谷歌的API的PHP客戶端
- 9. 使用谷歌客戶端獲取更新的事件使用谷歌客戶端php api
- 10. 關於使用谷歌客戶端api
- 11. SSLHandshakeError時,谷歌Analytics(分析)使用谷歌API客戶端庫的Python
- 12. Proguard的Android和谷歌API客戶端
- 13. 谷歌的Cloud Bigtable Python客戶端API
- 14. 與谷歌的API客戶端的PHP刷新令牌
- 15. 如何使用ValueRenderOption在谷歌的API的Python客戶端的谷歌牀單
- 16. 使用谷歌的API,JavaScript的客戶端的node.js
- 17. 谷歌API PHP客戶端 - 選擇正確的作用域
- 18. 獲取Gmail聯繫人PHP谷歌的API-PHP-客戶端0.6.0
- 19. Eclipse中使用谷歌客戶端api的註釋 - @Key
- 20. 谷歌服務帳戶認證與谷歌API的PHP客戶端使用日曆API
- 21. 後大通過谷歌的PHP客戶端API V3
- 22. 使用谷歌API客戶端無需客戶經理
- 23. 谷歌的API的PHP客戶端 - 獲取文件內容
- 24. 安裝谷歌客戶端庫谷歌分析PHP
- 25. PHP谷歌分析API - 簡單查詢
- 26. Symfony2的谷歌API,如何使用谷歌的客戶
- 27. 谷歌Analytics(分析)API獲取用戶ID /客戶端ID
- 28. 如何manuplate谷歌的API PHP客戶端
- 29. 谷歌API客戶端的PHP - MKDIR():權限被拒絕
- 30. 更新谷歌文檔與谷歌API api客戶端
約旦,這將使用java/python,我不想使用它們中的任何一個。我想要一些php命令,這將類似於INSERT。 – Aps18
PHP客戶端支持加載作業。邁克爾的回答如下。 –