Installation guide
echo $item['error']['S'] . "\n";
}
Deleting items
To delete an item you must use the DeleteItem() method. The following example scans through a table and deletes
every item one by one.
$scan = $client->getIterator('Scan', array('TableName' => 'errors'));
foreach ($scan as $item) {
$client->deleteItem(array(
'TableName' => 'errors',
'Key' => array(
'id' => array('N' => $item['id']['N']),
'time' => array('N' => $item['time']['N'])
)
));
}
You can also delete items in batches of up to 25 items using the BatchWriteItem() method.
Deleting a table
Warning
Deleting a table will also permanently delete all of its contents.
Now that you've taken a quick tour of the PHP client for Amazon DynamoDB, you will want to clean up by deleting
the resources you created.
$client->deleteTable(array(
'TableName' => 'errors'
));
$client->waitUntilTableNotExists(array(
'TableName' => 'errors'
));
Local secondary indexes
Local secondary indexes (LSI) pair your table's leading hash key with an alternate range key, in order to enable
specific queries to run more quickly than they would using a standard composite primary key. The following code
samples will show how to create an Orders table with a hash key of CustomerId and a range key of OrderId, but also
include a local secondary index on the OrderDate attribute so that searching the table based by OrderDate can be
done with a Query operation instead of a Scan operation.
First you must create the table with the local secondary index. Note that the attributes referenced in the key schema
for the table and the index must all be declared in the AttributeDefinitions parameter. When you create a
local secondary index, you can specify which attributes get "projected" into the index using the Projection
parameter.
// Create an "Orders" table
$client->createTable(array(
'TableName' => 'Orders',
'AttributeDefinitions' => array(
array('AttributeName' => 'CustomerId', 'AttributeType' => 'N'),
array('AttributeName' => 'OrderId', 'AttributeType' => 'N'),
array('AttributeName' => 'OrderDate', 'AttributeType' => 'N'),
),
Amazon DynamoDB
70