使用PHP从SimpleDB获取域列表

时间:2012-09-01 11:17:05

标签: php amazon-simpledb

我正在尝试使用PHP和官方Amazon AWS PHP SDK从SimpleDB获取域列表。我的代码得到了一些东西,但似乎是在循环错误的东西。

这是我的代码:

<?php
// Include the SDK
require_once 'sdk.class.php';

// Include the SDK
$sdb = new AmazonSDB();

$domainList = $sdb->listDomains();

echo "<pre>";
print_r($domainList, false);
echo "</pre>";

echo "<br><br><br>";

if ($domainList) {
  foreach ($domainList as $domainName) {

    $domain_name = $domainName->ListDomainsResult->DomainName;
    echo "Domain: " . $domain_name . "<br>";

  }
}

echo "<br><br><br>";

$request_id = $response->body->ResponseMetadata->RequestId;
$cost = $response->body->ResponseMetadata->BoxUsage;

echo "Request ID: " . $request_id . "<br>";
echo "Cost: " . $cost . "<br>";

?>

我得到以下输出的那一刻

Domain: 
Domain: test05
Domain: 

我应该得到:

test05
test06
test07

1 个答案:

答案 0 :(得分:1)

比我想象的容易。有一个更容易使用的命令:

以下是代码:

<?php
// Include the SDK
require_once 'sdk.class.php';

// Include the SDK
$sdb = new AmazonSDB();

// Get list of domains
$domains = $sdb->get_domain_list();

// echo "<pre>";
// print_r($domains, false);
// echo "</pre>";

foreach ($domains as $domain)
{ 
  echo "Domain: " . $domain . "<br>";
}
?>