Download sample php library from the link http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1135
Extract the zip file and put it in the location that you need that to be.
The folder structure will be like this.

We have to provide the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to every file to get connected to the database.
Now to get the list of all the domains we have to do these steps.
1.Open a clean copy of ListDomainsSample.php.
2.Remove any comment marks from the invokeListDomains($service, $request); line and add the following line after the @TODO: set request line:
$request = new Amazon_SimpleDB_Model_ListDomains();
3.Run the sample.
Amazon SimpleDB returns the list of domains within the account
Code for ListDomainsSample.php
<?php
/**
* PHP Version 5
*
* @category Amazon
* @package Amazon_SimpleDB
* @copyright Copyright 2008 Amazon Technologies, Inc.
* @link http://aws.amazon.com
* @license http://aws.amazon.com/apache2.0 Apache License, Version 2.0
* @version 2007-11-07
*/
/*******************************************************************************
* __ _ _ ___
* ( )( \/\/ )/ __)
* /__\ \ / \__ \
* (_)(_) \/\/ (___/
*
* Amazon Simple DB PHP5 Library
* Generated: Thu Aug 28 06:20:51 PDT 2008
*
*/
/**
* List Domains Sample
*/
include_once (‘.config.inc.php’);
/************************************************************************
* Instantiate Implementation of Amazon SimpleDB
*
* AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants
* are defined in the .config.inc.php located in the same
* directory as this sample
***********************************************************************/
$service = new Amazon_SimpleDB_Client(’1T477KF4HAV4SWT4T982′,
’622gIa+NcAhJFe2ulJ3XBrd5NRIUb2OhkCTjn5uR’);
/************************************************************************
* Uncomment to try out Mock Service that simulates Amazon_SimpleDB
* responses without calling Amazon_SimpleDB service.
*
* Responses are loaded from local XML files. You can tweak XML files to
* experiment with various outputs during development
*
* XML files available under Amazon/SimpleDB/Mock tree
*
***********************************************************************/
// $service = new Amazon_SimpleDB_Mock();
/************************************************************************
* Setup request parameters and uncomment invoke to try out
* sample for List Domains Action
***********************************************************************/
// @TODO: set request. Action can be passed as Amazon_SimpleDB_Model_ListDomainsRequest
// object or array of parameters
require_once (‘Amazon/SimpleDB/Model/ListDomainsRequest.php’);
$request = new Amazon_SimpleDB_Model_ListDomainsRequest();
invokeListDomains($service, $request);
/**
* List Domains Action Sample
* The ListDomains operaton lists all domains associated with the Access Key ID. It returns
* domain names up to the limit set by MaxNumberOfDomains. A NextToken is returned if there are more
* than MaxNumberOfDomains domains. Calling ListDomains successive times with the
* NextToken returns up to MaxNumberOfDomains more domain names each time.
*
* @param Amazon_SimpleDB_Interface $service instance of Amazon_SimpleDB_Interface
* @param mixed $request Amazon_SimpleDB_Model_ListDomains or array of parameters
*/
function invokeListDomains(Amazon_SimpleDB_Interface $service, $request)
{
try {
$response = $service->listDomains($request);
// echo (“Service Response<br />”);
// echo (“=============================================================================\n”);
//echo(” ListDomainsResponse<br />”);
if ($response->isSetListDomainsResult()) { ?><title>Create and Listing of Domains —— Amazon Simple DB Test by Sreeraj</title>
<h2 style=”color:#FF0000; font-family:Arial, Helvetica, sans-serif;”>
<?php echo(“Domains ( Tables )<br />”);?></h2>
<?php
$listDomainsResult = $response->getListDomainsResult();
$domainNameList = $listDomainsResult->getDomainName();?>
<table border=”1″ cellpadding=”5″ style=” border-collapse:collapse; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:14px; margin-bottom:20px;”>
<tr>
<th>Domain Name</th>
<th>Actions</th>
</tr>
<?php foreach ($domainNameList as $domainName) { ?>
<tr>
<td><?php echo(” ” . $domainName);?></td>
<td><a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”DeleteDomainSample.php?dom_name=<?php echo $domainName;?>” onClick=”return confirm(‘Do You want to delete Domain <?php echo $domainName;?>?’);”>[ Delete ]</a> <a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”SimpleCrud.php?dom_name=<?php echo $domainName;?>”>[ C R U D ]</a></td>
</tr>
<?php }?>
</table>
<a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”CreateDomainSample.php”>[ Add New Domain ]</a>
<?php if ($listDomainsResult->isSetNextToken())
{
// echo(” NextToken<br />”);
// echo(” ” . $listDomainsResult->getNextToken() . “\n”);
}
}
if ($response->isSetResponseMetadata()) {
//echo(” ResponseMetadata<br />”);
$responseMetadata = $response->getResponseMetadata();
if ($responseMetadata->isSetRequestId())
{
// echo(” RequestId\n”);
// echo(” ” . $responseMetadata->getRequestId() . “\n”);
}
if ($responseMetadata->isSetBoxUsage())
{
// echo(” BoxUsage\n”);
// echo(” ” . $responseMetadata->getBoxUsage() . “\n”);
}
}
} catch (Amazon_SimpleDB_Exception $ex) {
echo(“Caught Exception: ” . $ex->getMessage() . “\n”);
echo(“Response Status Code: ” . $ex->getStatusCode() . “\n”);
echo(“Error Code: ” . $ex->getErrorCode() . “\n”);
echo(“Error Type: ” . $ex->getErrorType() . “\n”);
echo(“Request ID: ” . $ex->getRequestId() . “\n”);
echo(“XML: ” . $ex->getXML() . “\n”);
}
}
Now lets see how to create a new domain in the database.
1.Open a clean copy of CreateDomainSample.php.
2.Remove any comment marks from the invokeCreateDomain($service, $request); line and add the following lines after the // @TODO: set request line:
require_once (‘Amazon/SimpleDB/Model/CreateDomain.php’);
$request = new Amazon_SimpleDB_Model_CreateDomain();
$request->setDomainName(‘MyStore’);
3.Run the sample.
The MyStore domain is created.
Code for CreateDomainSample.php
<?php
/**
* PHP Version 5
*
* @category Amazon
* @package Amazon_SimpleDB
* @copyright Copyright 2008 Amazon Technologies, Inc.
* @link http://aws.amazon.com
* @license http://aws.amazon.com/apache2.0 Apache License, Version 2.0
* @version 2007-11-07
*/
/*******************************************************************************
* __ _ _ ___
* ( )( \/\/ )/ __)
* /__\ \ / \__ \
* (_)(_) \/\/ (___/
*
* Amazon Simple DB PHP5 Library
* Generated: Thu Aug 28 06:20:51 PDT 2008
*
*/
/**
* Create Domain Sample
*/
include_once (‘.config.inc.php’);
/************************************************************************
* Instantiate Implementation of Amazon SimpleDB
*
* AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants
* are defined in the .config.inc.php located in the same
* directory as this sample
***********************************************************************/
$service = new Amazon_SimpleDB_Client(’1T477KF4HAV4SWT4T982′,
’622gIa+NcAhJFe2ulJ3XBrd5NRIUb2OhkCTjn5uR’);
/************************************************************************
* Uncomment to try out Mock Service that simulates Amazon_SimpleDB
* responses without calling Amazon_SimpleDB service.
*
* Responses are loaded from local XML files. You can tweak XML files to
* experiment with various outputs during development
*
* XML files available under Amazon/SimpleDB/Mock tree
*
***********************************************************************/
// $service = new Amazon_SimpleDB_Mock();
/************************************************************************
* Setup request parameters and uncomment invoke to try out
* sample for Create Domain Action
***********************************************************************/
// @TODO: set request. Action can be passed as Amazon_SimpleDB_Model_CreateDomainRequest
// object or array of parameters
require_once (‘Amazon/SimpleDB/Model/CreateDomainRequest.php’);
$request = new Amazon_SimpleDB_Model_CreateDomainRequest();
// Edited By Sreeraj 29/11/08
if(isset($_POST) && !empty($_POST))
{print “<pre>”;
print_r($_POST);
$domain_name = $_POST['domain'];
$request->setDomainName($domain_name);
invokeCreateDomain($service, $request);
}
/**
* Create Domain Action Sample
* The CreateDomain operation creates a new domain. The domain name must be unique
* among the domains associated with the Access Key ID provided in the request. The CreateDomain
* operation may take 10 or more seconds to complete.
*
* @param Amazon_SimpleDB_Interface $service instance of Amazon_SimpleDB_Interface
* @param mixed $request Amazon_SimpleDB_Model_CreateDomain or array of parameters
*/
function invokeCreateDomain(Amazon_SimpleDB_Interface $service, $request)
{
try {
$response = $service->createDomain($request);
header(“Location: SimpledbManage.php”);
} catch (Amazon_SimpleDB_Exception $ex) {
echo(“Caught Exception: ” . $ex->getMessage() . “\n”);
echo(“Response Status Code: ” . $ex->getStatusCode() . “\n”);
echo(“Error Code: ” . $ex->getErrorCode() . “\n”);
echo(“Error Type: ” . $ex->getErrorType() . “\n”);
echo(“Request ID: ” . $ex->getRequestId() . “\n”);
echo(“XML: ” . $ex->getXML() . “\n”);
}
}
?>
<html>
<head>
<title>Create and Listing of Domains —— Amazon Simple DB Test by Sreeraj</title>
<script type=”text/javascript” src=”jquery.js”></script>
<script type=”text/javascript”>
function find_total_elements()
{
var tot = 0;
var id_value = 0;
jQuery(document).find(“input[@id^=first_name]“).each(function()
{
tot = tot + 1
});
id_value = tot + 1;
/* for updating the hidden field */
jQuery(“#tot_product”).val(id_value);
/* Product form for adult */
next_fields = ” <p id=\”product_”+id_value+”\” style=\”width:450px;\”><span style=\”font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#006600; font-weight:bold;\”>Field Name</span>”;
next_fields +=”<input type=\”hidden\” name=\”type[]\” id=\”type\” value=\”adult\”/>”
//next_fields += ” <tr><td width=\”35%\”><font color=\”#333333\” face=\”Verdana\” size=\”1\”><span style=\”font-size: 8.5pt; font-family: Verdana; color: rgb(51, 51, 51);\”>First Name </span></font></td><td width=\”32%\”><font color=\”#333333\” face=\”Verdana\” size=\”1\”><span style=\”font-size: 8.5pt; font-family: Verdana; color: rgb(51, 51, 51);\”>Middle Name </span></font></td><td width=\”33%\”><font color=\”#333333\” face=\”Verdana\” size=\”1\”><span style=\”font-size: 8.5pt; font-family: Verdana; color: rgb(51, 51, 51);\”>Last Name</span></font></td></tr><tr>”;
next_fields += “<td height=\”24\” align=\”center\” valign=\”top\”><input type=\”text\” name=\”firstname[]\” id=\”first_name_”+id_value+”\” style=\”width:130px;\” />”;
div_id = id_value – 1;
$( “#product_”+div_id+”" ).after( next_fields );
}
</script>
</head>
<body>
<form method=”post”>
<h2 style=”color:#FF0000; font-family:Arial, Helvetica, sans-serif;”>Create Domains ( Tables )</h2>
<span style=”font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#006600; font-weight:bold;”>Domain name: </span><input type=”text” name=”domain” id=”domain” /><br />
<p id=”product_1″ style=”width:460px;height:10px;text-align:center”><span style=”font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#006600; font-weight:bold;”>Field Name</span>
<input type=”hidden” name=”tot_product” id=”tot_product” value=”1″/>
<input type=”hidden” name=”type[]” id=”type” value=”adult”/>
<input type=”text” name=”firstname[]” id=”first_name_1″ style=”width:130px;” />
<input name=”button2″ type=”button” id=”button” onClick=”find_total_elements();” value=”Add Fields” />
<input type=”submit” name=”submit” id=”submit” value=”Create” />
</form>
<a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”ListDomainsSample.php”>[ List Domains ]</a>
</body>
</html>
Now lets see how to create a simple crud.
1. For this we have to pass the domain name as a get variable.
2. Then by query we will get the data present in the domain to a variable as array.
3. The we can format it in a table format and crud is obtained.
Code for SimpleCrud.php
<?php
/**
* PHP Version 5
*
* @category Amazon
* @package Amazon_SimpleDB
* @copyright Copyright 2008 Amazon Technologies, Inc.
* @link http://aws.amazon.com
* @license http://aws.amazon.com/apache2.0 Apache License, Version 2.0
* @version 2007-11-07
*/
/*******************************************************************************
* __ _ _ ___
* ( )( \/\/ )/ __)
* /__\ \ / \__ \
* (_)(_) \/\/ (___/
*
* Amazon Simple DB PHP5 Library
* Generated: Thu Aug 28 06:20:51 PDT 2008
*
*/
/**
* Query With Attributes Sample
*/
include_once (‘.config.inc.php’);
/************************************************************************
* Instantiate Implementation of Amazon SimpleDB
*
* AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants
* are defined in the .config.inc.php located in the same
* directory as this sample
***********************************************************************/
$service = new Amazon_SimpleDB_Client(’1T477KF4HAV4SWT4T982′,
’622gIa+NcAhJFe2ulJ3XBrd5NRIUb2OhkCTjn5uR’);
/************************************************************************
* Uncomment to try out Mock Service that simulates Amazon_SimpleDB
* responses without calling Amazon_SimpleDB service.
*
* Responses are loaded from local XML files. You can tweak XML files to
* experiment with various outputs during development
*
* XML files available under Amazon/SimpleDB/Mock tree
*
***********************************************************************/
// $service = new Amazon_SimpleDB_Mock();
/************************************************************************
* Setup request parameters and uncomment invoke to try out
* sample for Query With Attributes Action
***********************************************************************/
// @TODO: set request. Action can be passed as Amazon_SimpleDB_Model_QueryWithAttributesRequest
// object or array of parameters
require_once (‘Amazon/SimpleDB/Model/QueryWithAttributesRequest.php’);
$request = new Amazon_SimpleDB_Model_QueryWithAttributesRequest();
$domain = $_GET['dom_name'];
$request->setDomainName($domain);
//$request->setQueryExpression(“['Name' != '']“);
//$request->MyFunction();
invokeQueryWithAttributes($service, $request);
/**
* Query With Attributes Action Sample
* The QueryWithAttributes operation returns a set of item names and associated attributes.
* The query semantics of this operation are identical to the Query operation.
*
* @param Amazon_SimpleDB_Interface $service instance of Amazon_SimpleDB_Interface
* @param mixed $request Amazon_SimpleDB_Model_QueryWithAttributes or array of parameters
*/
function invokeQueryWithAttributes(Amazon_SimpleDB_Interface $service, $request)
{
try {
$response = $service->queryWithAttributes($request);
// echo (“Service Response\n”);
// echo (“=============================================================================\n”);
// echo(” QueryWithAttributesResponse\n”);
if ($response->isSetQueryWithAttributesResult()) {
// echo(” QueryWithAttributesResult<br />”);
$queryWithAttributesResult = $response->getQueryWithAttributesResult();
$itemList = $queryWithAttributesResult->getItem();
$dom = $_GET['dom_name'];
?><title>CRUD Using the Amazon SimpleDb————- Test Done by Sreeraj</title>
<h2 style=”color:#FF0000; font-family:Arial, Helvetica, sans-serif;”>Sample Data</h2>
<div align=”left” style=”margin-bottom:10px;”>
<a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”PutAttributesSample.php?dom_name=<?php echo $dom;?>”>[ Add New Record ]</a> <a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”SimpledbManage.php”>[ Manage Domains ]</a>
</div>
<table border=”1″ style=”border-collapse:collapse; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;” cellpadding=”5″ align=”left”>
<th colspan=”6″>Sample data</th>
<tr>
<th>Id</th>
<th>Name</th>
<th>Age</th>
<th colspan=”3″>Actions</th>
</tr>
<?php foreach ($itemList as $item) {?>
<?php //print “<pre>”;
//print_r($item);
// echo(” Item\n”);?>
<tr>
<td>
<?php if ($item->isSetName())
{
// echo(” Name\n”);
echo($item->getName());
}?>
</td>
<td>
<?php $attributeList = $item->getAttribute();
foreach ($attributeList as $attribute) {
//print “<pre>”;
//print_r($attribute);
//echo(” Attribute\n”);
if ($attribute->isSetName())
{
// echo(” Name\n”);
//echo(” ” . $attribute->getName() . “\n”);
}
if ($attribute->isSetValue() && $attribute->getName() == ‘Name’)
{
//echo(” Value\n”);
echo($attribute->getValue());
$name = $attribute->getValue();
}
}?>
</td>
<td>
<?php $attributeList = $item->getAttribute();
foreach ($attributeList as $attribute) {
//print “<pre>”;
//print_r($attribute);
//echo(” Attribute\n”);
if ($attribute->isSetName())
{
// echo(” Name\n”);
//echo(” ” . $attribute->getName() . “\n”);
}
if ($attribute->isSetValue() && $attribute->getName() == ‘Age’)
{
//echo(” Value\n”);
echo(” ” . $attribute->getValue());
}
}?>
</td>
<td><a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”GetAttributesSample.php?dom_name=<?php echo $dom;?>&ItemID=<?php echo $item->getName();?>”>[ View ]</a></td>
<td><a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”EditPage.php?dom_name=<?php echo $dom;?>&ItemID=<?php echo $item->getName();?>”>[ Edit ]</a></td>
<td><a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”DeleteAttributesSample.php?dom_name=<?php echo $dom;?>&ItemID=<?php echo $item->getName();?>” onClick=”return confirm(‘Do You want to delete <?php echo $name;?>?’);”>[ Delete ]</a></td>
<?php }?>
</tr>
</table>
<?php if ($queryWithAttributesResult->isSetNextToken())
{
//echo(” NextToken\n”);
//echo(” ” . $queryWithAttributesResult->getNextToken() . “\n”);
}
}
if ($response->isSetResponseMetadata()) {
// echo(” ResponseMetadata\n”);
$responseMetadata = $response->getResponseMetadata();
if ($responseMetadata->isSetRequestId())
{
//echo(” RequestId\n”);
//echo(” ” . $responseMetadata->getRequestId() . “\n”);
}
if ($responseMetadata->isSetBoxUsage())
{
// echo(” BoxUsage\n”);
// echo(” ” . $responseMetadata->getBoxUsage() . “\n”);
}
}
} catch (Amazon_SimpleDB_Exception $ex) {
echo(“Caught Exception: ” . $ex->getMessage() . “\n”);
echo(“Response Status Code: ” . $ex->getStatusCode() . “\n”);
echo(“Error Code: ” . $ex->getErrorCode() . “\n”);
echo(“Error Type: ” . $ex->getErrorType() . “\n”);
echo(“Request ID: ” . $ex->getRequestId() . “\n”);
echo(“XML: ” . $ex->getXML() . “\n”);
}
}
Now lets see how to add a new value to the domain
1. For this we have to pass the domain name as a get variable.
2. Then by the PutAttributes class we can insert the data into the domain.
3. Here we can make a form and the data that has to be inserted will be obtained from the post value.
4. When we submit a new record gets inserted into the domain.
Code for PutAttributesSample.php
<?php
/**
* PHP Version 5
*
* @category Amazon
* @package Amazon_SimpleDB
* @copyright Copyright 2008 Amazon Technologies, Inc.
* @link http://aws.amazon.com
* @license http://aws.amazon.com/apache2.0 Apache License, Version 2.0
* @version 2007-11-07
*/
/*******************************************************************************
* __ _ _ ___
* ( )( \/\/ )/ __)
* /__\ \ / \__ \
* (_)(_) \/\/ (___/
*
* Amazon Simple DB PHP5 Library
* Generated: Thu Aug 28 06:20:51 PDT 2008
*
*/
/**
* Put Attributes Sample
*/
include_once (‘.config.inc.php’);
/************************************************************************
* Instantiate Implementation of Amazon SimpleDB
*
* AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants
* are defined in the .config.inc.php located in the same
* directory as this sample
***********************************************************************/
$service = new Amazon_SimpleDB_Client(’1T477KF4HAV4SWT4T982′,
’622gIa+NcAhJFe2ulJ3XBrd5NRIUb2OhkCTjn5uR’);
/************************************************************************
* Uncomment to try out Mock Service that simulates Amazon_SimpleDB
* responses without calling Amazon_SimpleDB service.
*
* Responses are loaded from local XML files. You can tweak XML files to
* experiment with various outputs during development
*
* XML files available under Amazon/SimpleDB/Mock tree
*
***********************************************************************/
// $service = new Amazon_SimpleDB_Mock();
/************************************************************************
* Setup request parameters and uncomment invoke to try out
* sample for Put Attributes Action
***********************************************************************/
// @TODO: set request. Action can be passed as Amazon_SimpleDB_Model_PutAttributesRequest
// object or array of parameters
require_once (‘Amazon/SimpleDB/Model/PutAttributesRequest.php’);
require_once (‘Amazon/SimpleDB/Model/ReplaceableAttribute.php’);
$domainName = $_GET['dom_name'];
/*———————————————————————
| This Section is edited by Sreeraj So as to test the Amazon SimpleDb |
| |
———————————————————————–*/
if(isset($_POST) && !empty($_POST))
{
$id = rand(0,1000);
$name = $_POST['test_name'];
$age = $_POST['test_age'];
/************************************************************************
* Items are rows in the table where the Itemname represents the Id of that record
* Domain is the table
* Load Data:
* Name = Sreeraj
* Age = 22
***********************************************************************/
$itemName = ‘ID_’.$id;// This is the id of the one row
$attribute1 = new Amazon_SimpleDB_Model_ReplaceableAttribute();
$attribute1->withName(‘Name’)->withValue($name);
$attribute2 = new Amazon_SimpleDB_Model_ReplaceableAttribute();
$attribute2->withName(‘Age’)->withValue($age);
$attributeList = array($attribute1, $attribute2);
$request = new Amazon_SimpleDB_Model_PutAttributesRequest();
$request->withDomainName($domainName)->withItemName($itemName)->setAttribute
($attributeList);
invokePutAttributes($service, $request);
}
/**
* Put Attributes Action Sample
* The PutAttributes operation creates or replaces attributes within an item. You specify new attributes
* using a combination of the Attribute.X.Name and Attribute.X.Value parameters. You specify
* the first attribute by the parameters Attribute.0.Name and Attribute.0.Value, the second
* attribute by the parameters Attribute.1.Name and Attribute.1.Value, and so on.
* Attributes are uniquely identified within an item by their name/value combination. For example, a single
* item can have the attributes { “first_name”, “first_value” } and { “first_name”,
* second_value” }. However, it cannot have two attribute instances where both the Attribute.X.Name and
* Attribute.X.Value are the same.
* Optionally, the requestor can supply the Replace parameter for each individual value. Setting this value
* to true will cause the new attribute value to replace the existing attribute value(s). For example, if an
* item has the attributes { ‘a’, ’1′ }, { ‘b’, ’2′} and { ‘b’, ’3′ } and the requestor does a
* PutAttributes of { ‘b’, ’4′ } with the Replace parameter set to true, the final attributes of the
* item will be { ‘a’, ’1′ } and { ‘b’, ’4′ }, replacing the previous values of the ‘b’ attribute
* with the new value.
*
* @param Amazon_SimpleDB_Interface $service instance of Amazon_SimpleDB_Interface
* @param mixed $request Amazon_SimpleDB_Model_PutAttributes or array of parameters
*/
function invokePutAttributes(Amazon_SimpleDB_Interface $service, $request)
{
try {
$response = $service->putAttributes($request);
$domainName = $_GET['dom_name'];
header(“Location: SimpleCrud.php?dom_name=$domainName”);
} catch (Amazon_SimpleDB_Exception $ex) {?>
<input type=”button” value=”Reload Page” onClick=”window.location.reload()”>
<?php
echo(“Caught Exception: ” . $ex->getMessage() . “\n”);
echo(“Response Status Code: ” . $ex->getStatusCode() . “\n”);
echo(“Error Code: ” . $ex->getErrorCode() . “\n”);
echo(“Error Type: ” . $ex->getErrorType() . “\n”);
echo(“Request ID: ” . $ex->getRequestId() . “\n”);
echo(“XML: ” . $ex->getXML() . “\n”);
}
}
?>
<html>
<head>
<title>Insert Values into the database—— Amazon Simple DB Test by Sreeraj</title>
</head>
<body>
<h2 style=”color:#FF0000; font-family:Arial, Helvetica, sans-serif;”>Add new Record</h2>
<form method=”post”>
<span style=”font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#006600;”>Name:</span><input type=”text” name=”test_name” id=”test_name” />
<span style=”font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#006600;”>Age:</span><input type=”text” name=”test_age” id=”test_age” /><br />
<input type=”submit” name=”submit” value=”Submit” style=”margin-top:10px;” />
</form>
<a style=”text-decoration:none; font-family:Arial, Helvetica, sans-serif; font-size:12px;” href=”SimpleCrud.php?dom_name=<?php echo $domainName;?>”>[ C R U D ]</a>
</body>
</html>
Now lets see how to edit a value in the domain
1. For this we have to pass the domain name and ID as a get variables.
2. With the ID and the domain we can change the value in the database.
Code for EditPage.php
<?php
/**
* PHP Version 5
*
* @category Amazon
* @package Amazon_SimpleDB
* @copyright Copyright 2008 Amazon Technologies, Inc.
* @link http://aws.amazon.com
* @license http://aws.amazon.com/apache2.0 Apache License, Version 2.0
* @version 2007-11-07
*/
/*******************************************************************************
* __ _ _ ___
* ( )( \/\/ )/ __)
* /__\ \ / \__ \
* (_)(_) \/\/ (___/
*
* Amazon Simple DB PHP5 Library
* Generated: Thu Aug 28 06:20:51 PDT 2008
*
*/
/**
* Get Attributes Sample
*/
include_once (‘.config.inc.php’);
/************************************************************************
* Instantiate Implementation of Amazon SimpleDB
*
* AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants
* are defined in the .config.inc.php located in the same
* directory as this sample
***********************************************************************/
$service = new Amazon_SimpleDB_Client(’1T477KF4HAV4SWT4T982′,
’622gIa+NcAhJFe2ulJ3XBrd5NRIUb2OhkCTjn5uR’);
/************************************************************************
* Uncomment to try out Mock Service that simulates Amazon_SimpleDB
* responses without calling Amazon_SimpleDB service.
*
* Responses are loaded from local XML files. You can tweak XML files to
* experiment with various outputs during development
*
* XML files available under Amazon/SimpleDB/Mock tree
*
***********************************************************************/
// $service = new Amazon_SimpleDB_Mock();
/************************************************************************
* Setup request parameters and uncomment invoke to try out
* sample for Get Attributes Action
***********************************************************************/
// @TODO: set request. Action can be passed as Amazon_SimpleDB_Model_GetAttributesRequest
// object or array of parameters
require_once (‘Amazon/SimpleDB/Model/GetAttributesRequest.php’);
$request = new Amazon_SimpleDB_Model_GetAttributesRequest();
// Edited By Sreeraj 29/11/08
// print_r($_GET);
$domain = $_GET['dom_name'];
$Item = $_GET['ItemID'];
$request->setDomainName($domain);
$request->setItemName($Item);
invokeGetAttributes($service, $request);
/**
* Get Attributes Action Sample
* Returns all of the attributes associated with the item. Optionally, the attributes returned can be limited to
* the specified AttributeName parameter.
* If the item does not exist on the replica that was accessed for this operation, an empty attribute is
* returned. The system does not return an error as it cannot guarantee the item does not exist on other
* replicas.
*
* @param Amazon_SimpleDB_Interface $service instance of Amazon_SimpleDB_Interface
* @param mixed $request Amazon_SimpleDB_Model_GetAttributes or array of parameters
*/
function invokeGetAttributes(Amazon_SimpleDB_Interface $service, $request)
{
try {
$response = $service->getAttributes($request);
// echo (“Service Response\n”);
// echo (“=============================================================================\n”);
// echo(” GetAttributesResponse\n”);
if ($response->isSetGetAttributesResult()) {
//echo(” GetAttributesResult<br />”);
$getAttributesResult = $response->getGetAttributesResult();
$attributeList = $getAttributesResult->getAttribute();
$domain = $_GET['dom_name'];
$Item = $_GET['ItemID'];
?><title>Edit Page</title>
<h2 style=”color:#FF0000; font-family:Arial, Helvetica, sans-serif;”>Edit Page</h2>
<form action=”EditAttributes.php?dom_name=<?php echo $domain;?>&Item=<?php echo $Item;?>” method=”post”>
<table border=”1″ style=”border-collapse:collapse; margin-bottom:20px;” cellpadding=”5″>
<?php foreach ($attributeList as $attribute) {?>
<tr>
<td>
<?php if ($attribute->isSetName())
{?>
<input type=”text” name=”name[]” id=”name” value=”<?php echo($attribute->getName());?>” />
<?php }?>
</td>
<td>
<?php if ($attribute->isSetValue())
{?>
<input type=”text” name=”value[]” id=”value” value=”<?php echo($attribute->getValue());?>” />
<?php }?>
</td>
</tr>
<?php }?>
</table>
<input type=”submit” name=”submit” value=”Update” />
</form>
<?php }
if ($response->isSetResponseMetadata()) {
// echo(” ResponseMetadata\n”);
$responseMetadata = $response->getResponseMetadata();
if ($responseMetadata->isSetRequestId())
{
// echo(” RequestId\n”);
// echo(” ” . $responseMetadata->getRequestId() . “\n”);
}
if ($responseMetadata->isSetBoxUsage())
{
// echo(” BoxUsage\n”);
// echo(” ” . $responseMetadata->getBoxUsage() . “\n”);
}
}
} catch (Amazon_SimpleDB_Exception $ex) {
echo(“Caught Exception: ” . $ex->getMessage() . “\n”);
echo(“Response Status Code: ” . $ex->getStatusCode() . “\n”);
echo(“Error Code: ” . $ex->getErrorCode() . “\n”);
echo(“Error Type: ” . $ex->getErrorType() . “\n”);
echo(“Request ID: ” . $ex->getRequestId() . “\n”);
echo(“XML: ” . $ex->getXML() . “\n”);
}
}
?>
<input type=”button” value=”Back to Previous Page” onClick=”javascript: history.go(-1)”>




