Installation guide
echo $tableName . "\n";
}
Iterating over all tables
The result of a listTables() operation might be truncated. Because of this, it is usually better to use an iterator
to retrieve a complete list of all of the tables owned by your account in a specific region. The iterator will
automatically handle sending any necessary subsequent requests.
$iterator = $client->getIterator('ListTables');
foreach ($iterator as $tableName) {
echo $tableName . "\n";
}
Tip
You can convert an iterator to an array using the toArray() method of the iterator.
Adding items
You can add an item to our errors table using the putItem() method of the client.
$time = time();
$result = $client->putItem(array(
'TableName' => 'errors',
'Item' => $client->formatAttributes(array(
'id' => 1201,
'time' => $time,
'error' => 'Executive overflow',
'message' => 'no vacant areas'
)),
'ReturnConsumedCapacity' => 'TOTAL'
));
// The result will always contain ConsumedCapacityUnits
echo $result->getPath('ConsumedCapacity/CapacityUnits') . "\n";
As you can see, the formatAttributes() method of the client can be used to more easily format the attributes
of the item. Alternatively, you can provide the item attributes without using the helper method:
$result = $client->putItem(array(
'TableName' => 'errors',
'Item' => array(
'id' => array('N' => '1201'),
'time' => array('N' => $time),
'error' => array('S' => 'Executive overflow'),
'message' => array('S' => 'no vacant areas')
)
));
You can also add items in batches of up to 25 items using the BatchWriteItem() method. Please see the example as
shown in the Local secondary indexes section of this guide.
There is also a higher-level abstraction in the SDK over the BatchWriteItem operation called the
WriteRequestBatch that handles queuing of write requests and retrying of unprocessed items. Please see the
Using the WriteRequestBatch section of this guide for more information.
Amazon DynamoDB
67