Bigquery + PHP examples

后端 未结 4 1341
时光说笑
时光说笑 2020-12-03 19:42

Can somebody provide working example of using the Bigquery API with PHP. I see there are examples for python and java but could not find anything for PHP.

Here is th

4条回答
  •  感情败类
    2020-12-03 19:52

    I had a lot of issues finding examples. This is a basic async query, but can demonstrate current PHP API usage, you can see the Python/Java example of the API for async queries here: https://developers.google.com/bigquery/querying-data

    Please note, I am not referencing how to setup $client credentials, as it is well documented elsewhere.

        $bq = new Google_BigqueryService($client);
    
        //build query
        $sql = 'select * from example.table LIMIT 10';
    
        $job = new Google_Job();
        $config = new Google_JobConfiguration();
        $queryConfig = new Google_JobConfigurationQuery();
        $config->setQuery($queryConfig);
    
        $job->setConfiguration($config);
        $queryConfig->setQuery($sql);
    
        $insert = new Google_Job($bq->jobs->insert(PROJECT_ID,$job));
        $jr = $insert->getJobReference();
        $jobId = $jr['jobId'];
    
        $res = new Google_GetQueryResultsResponse($bq->jobs->getQueryResults(PROJECT_ID, $jobId));
    
    //see the results made it as an object ok:
            var_dump($results);
    

提交回复
热议问题