我正在尝试使用aws php sdk运行一个athena查询。但是我得到了一个空数组作为结果。谁能告诉我我的代码有什么问题吗
require '/usr/bin/vendor/autoload.php';
use Aws\Athena\AthenaClient;
$options = [
'version' => 'latest',
'region' => 'eu-west-1',
'credentials' => [
'key' => 'mykey',
'secret' => 'mysecret']
];
$athenaClient = new Aws\Athena\AthenaClient($options);
$result = $athenaClient->startQueryExecution([
'QueryExecutionContext' => [
'Database' => 'mydbname',
],
'QueryString' => 'select * from mytable limit 3', // REQUIRED
'ResultConfiguration' => [ // REQUIRED
'EncryptionConfiguration' => [
'EncryptionOption' => 'SSE_S3' // REQUIRED
],
'OutputLocation' => 's3://mybucket/', // REQUIRED
],
]);
print_r($result);
以下是我看到的结果
Aws\Result Object ( [data:Aws\Result:private] => Array ( [QueryExecutionId] => 21221212121212121 [@metadata] => Array ( [statusCode] => 200 [effectiveUri] => https://athena.eu-west-1.amazonaws.com [headers] => Array ( [date] => Tue, 28 Feb 2023 16:09:57 GMT [content-type] => application/x-amz-json-1.1 [content-length] => 59 [connection] => keep-alive [x-amzn-requestid] => 3232323232323232 ) [transferStats] => Array ( [http] => Array ( [0] => Array ( ) ) ) ) ) [monitoringEvents:Aws\Result:private] => Array ( ) )
1条答案
按热度按时间mnowg1ta1#
对于Athena查询,您需要开始执行,等待查询完成,然后获取结果。查看文档中的示例代码和更多解释:https://docs.aws.amazon.com/athena/latest/ug/code-samples.html
对于您的查询,您确实成功地在
$result
变量中获得了QueryExecutionId
,这是StartQueryExecution
应该返回的唯一内容。https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-athena-2017-05-18.html#startqueryexecution然后可以使用
GetQueryExecution
检查状态:https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-athena-2017-05-18.html#getqueryexecution最后,使用
GetQueryResults
获取查询结果。https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-athena-2017-05-18.html#getqueryresults