我正在尝试创建一个注册页面,其中用户名和密码将存储在BigQuery的users表中。我正在使用PHP,并在php的bigquery api上尝试了不同的函数来做到这一点,但到目前为止,每一次尝试都失败了。将是伟大的,如果有人可以协助语法或其他步骤可能对我有用的代码片段。
我已经尝试了所有可用的google参考文档,但没有任何文档对insert语句有足够的详细信息。由于这些是小的和单一的插入,我将不需要流式插入。
$request =新Google_Service_Bigquery_QueryRequest();
$request->setQuery("INSERT INTO `Testing.users` (user,password,role) VALUE ('$userid','$password','$role')");
$response = $bigquery->jobs->query($projectId, $request);发布于 2019-09-21 18:46:35
强烈建议使用流插入。与2-3秒的同步查询相比,它的速度更快,最大约为300ms。
composer require google/cloud-bigquery但是,如果您想要插入作业
您可以使用:
use Google\Cloud\BigQuery\BigQueryClient;
$bigQuery = new BigQueryClient([
'projectId' => $projectId,
]);
$dataset = $bigQuery->dataset($datasetId);
$sql="INSERT INTO `test_table` (`name`, `title`) VALUES ('Brent Shaffer', 'PHP Developer')";
$queryConfig = $bigQuery->query($sql)->defaultDataset($dataset);
$bigQuery->runQuery($queryConfig);对于流插入,示例如下
$bigQuery = new BigQueryClient([
'projectId' => $projectId,
]);
$dataset = $bigQuery->dataset($datasetId);
$table = $dataset->table($tableId);
$insertResponse = $table->insertRows([
['col1' => $val1,'col2' => $val2],// <-- this was a row
// additional rows can go here
]);
if ($insertResponse->isSuccessful()) {
print('Data streamed into BigQuery successfully' . PHP_EOL);
} else {
foreach ($insertResponse->failedRows() as $row) {
foreach ($row['errors'] as $error) {
printf('%s: %s' . PHP_EOL, $error['reason'], $error['message']);
}
}
}https://stackoverflow.com/questions/58038807
复制相似问题