我希望得到来自bigquery的响应而没有循环属性f,v
$response = $bigquery->jobs->query($projectId, $request);
$rows = $response->getRows();
foreach($rows as $data){
$date = date('Y-m-d H:i:s',$data->f[6]->v);
$response[$count]["app_id"] = $data->f[0]->v;
$response[$count]["uid"] = $data->f[1]->v;
$response[$count]["account"] = $data->f[2]->v;
$response[$count]["action"] = $data->f[9]->v;
$response[$count]["ip"] = $data->f[5]->v;
$response[$count]["status"] = $data->f[11]->v;
$response[$count]["created_date"] = $date;
}
预期
$response = $bigquery->jobs->query($projectId, $request);
$rows = $response->getRows();
echo $rows[0]["app_id"];
怎么样?可能吗?任何人都可以帮我找到解决方案吗?
答案 0 :(得分:2)
我使用此查询作为示例:
SELECT repository_url,
repository_has_downloads
FROM publicdata:samples.github_timeline
LIMIT 10
首先,您需要从" name"中构建一个schema_keys
数组。属性。
$fields = $response->getSchema()->getFields();
$schema_keys = array_flip(array_map(function($o){ return $o->name; }, $fields));
这将保留结果列名==>索引号:
Array
(
[repository_url] => 0
[repository_has_downloads] => 1
)
然后当你循环:
foreach ($rows as $r) {
// you need to convert the TableRow in TableCell here
$table_cell = $r->getF();
// then you can read columns from it like this
echo $table_cell[$schema_keys['repository_url']]->getV();
echo $table_cell[$schema_keys['repository_has_downloads']]->getV();
}