Installation guide
After creating a domain, you are ready to start putting data into it. Domains consist of items, which are described by
attribute name-value pairs. Items are added to a domain using the PutAttributes operation.
$client->putAttributes(array(
'DomainName' => 'mydomain',
'ItemName' => 'test',
'Attributes' => array(
array('Name' => 'a', 'Value' => 1, 'Replace' => true),
array('Name' => 'b', 'Value' => 2),
)
));
Note
When you put attributes, notice that the Replace parameter is optional, and set to false by default. If you do not
explicitly set Replace to true, a new attribute name-value pair is created each time; even if the Name value
already exists in your Amazon SimpleDB domain.
Retrieving items
GetAttributes
We can check to see if the item was added correctly by retrieving the specific item by name using the GetAttribute
operation.
$result = $client->getAttributes(array(
'DomainName' => 'mydomain',
'ItemName' => 'test',
'Attributes' => array(
'a', 'b'
),
'ConsistentRead' => true
));
Notice that we set the ConsistentRead option to true. Amazon SimpleDB keeps multiple copies of each domain. A
successful write (using PutAttributes, BatchPutAttributes, DeleteAttributes, BatchDeleteAttributes, CreateDomain, or
DeleteDomain) guarantees that all copies of the domain will durably persist. Amazon SimpleDB supports two read
consistency options: eventually consistent read and consistent read. A consistent read (using Select or GetAttributes
with ConsistentRead=true) returns a result that reflects all writes that received a successful response prior to the
read.
You can find out more about consistency and Amazon SimpleDB in the service's developer guide on consistency.
Select
You can retrieve attributes for items by name, but Amazon SimpleDB also supports the Select operation. The Select
operation returns a set of Attributes for ItemNames that match the select expression. Select is similar to the standard
SQL SELECT statement.
Let's write a select query that will return all items withe the a attribute set to 1.
$result = $client->select(array(
'SelectExpression' => "select * from mydomain where a = '1'"
));
foreach ($result['Items'] as $item) {
echo $item['Name'] . "\n";
var_export($item['Attributes']);
}
Amazon SimpleDB
115