Hey, I’m trying to have a little fun with SimpleDB. In order to play with data (delete, mostly) I needed to write a simple function to get my informations. Now be warned, it’s very poor code, but it’ll allow you to see and delete your data easely. Anyone willing to write phpSimpleDBAdmin ? Here it is :

  1. $this->_helper->viewRenderer->setNoRender(true);
  2. $this->_helper->layout->disableLayout(true);
  3. echo “<h2> Current domains </h2>”;
  4. // Build a link to show all domains
  5. $Admin = new Admin();
  6. $domains = $Admin->ListDomains();
  7. foreach ($domains as $key=>$value)
  8. {
  9. echo “<a href=”showdomain?d=$value”> $value</a> “;
  10. }
  11. if(isset($_GET[‘d’]))
  12. {
  13. echo “<h2> “.$_GET[‘d’].” data</h2>”;
  14. echo “#ADD a pre HERE”;
  15. $data = $Admin->getDomainData($_GET[‘d’]);
  16. print_r($data);
  17. foreach ($data as $k=>$v)
  18. {
  19. foreach ($v as $items=>$array)
  20. {
  21. echo “<br>Item id : $items actions : <a href=”\”/admin/deleteitem?d=”.$_GET[‘d’].”&i=$items\””>delete</a>”;
  22. }
  23. }
  24. }

Now, this function uses 2 other functions :

  1. public function ListDomains()
  2. {
  3. $request = new Amazon_SimpleDB_Model_ListDomainsRequest();
  4. $response = $this->service->listDomains($request);
  5. if ($response->isSetListDomainsResult()) {
  6. $listDomainsResult = $response->getListDomainsResult();
  7. $domainNameList  =  $listDomainsResult->getDomainName();
  8. foreach ($domainNameList as $domainName) {
  9. $data[] = $domainName;
  10. }
  11. }
  12. return $data;
  13. }
  14. public function getDomainData($d)
  15. {
  16. $request = new Amazon_SimpleDB_Model_QueryWithAttributesRequest();
  17. $request->setDomainName($d);
  18. $response = $this->service->queryWithAttributes($request);
  19. $data = array();
  20. if ($response->isSetQueryWithAttributesResult()) {
  21. $queryWithAttributesResult = $response->getQueryWithAttributesResult();
  22. $itemList = $queryWithAttributesResult->getItem();
  23. foreach ($itemList as $item) {
  24. $attributeList = $item->getAttribute();
  25. foreach ($attributeList as $attribute) {
  26. $attribs[$attribute->getName()] = $attribute->getValue();
  27. }
  28. $data[] = array($item->getName() => $attribs);
  29. $attribs = “”;
  30. }
  31. return $data;
  32. }
  33. }

Note : replace #Add a pre here# by the pre tag in html.

Advertisements