Gets the values of one or more items and its attributes by primary key (composite primary key, only).
Narrow the scope of the query using comparison operators on the RangeKeyValue
of
the composite key. Use the ScanIndexForward
parameter to get results in forward or
reverse order by range key.
Access
public
Parameters
Parameter |
Type |
Required |
Description |
---|---|---|---|
|
Optional |
An associative array of parameters that can have the following keys:
|
Returns
Type |
Description |
---|---|
A |
Examples
Scan the database for information.
Examples for Scan.
// Instantiate the class $dynamodb = new AmazonDynamoDB(); $table_name = 'my-table' . time(); #################################################################### # Create a new DynamoDB table $response = $dynamodb->create_table(array( 'TableName' => $table_name, 'KeySchema' => array( 'HashKeyElement' => array( 'AttributeName' => 'id', 'AttributeType' => AmazonDynamoDB::TYPE_NUMBER, ), 'RangeKeyElement' => array( 'AttributeName' => 'date', 'AttributeType' => AmazonDynamoDB::TYPE_NUMBER, ), ), 'ProvisionedThroughput' => array( 'ReadCapacityUnits' => 10, 'WriteCapacityUnits' => 5, ), )); var_dump($response->isOK()); if (!$response->isOK()) { die('Table creation failed.'); } // Sleep and poll during table creation do { sleep(1); $response = $dynamodb->describe_table(array( 'TableName' => $table_name )); } while ((string) $response->body->Table->TableStatus !== 'ACTIVE'); #################################################################### # Add data to the table // Add items to the batch $response = $dynamodb->batch_write_item(array( 'RequestItems' => array( $table_name => array( array( 'PutRequest' => array( 'Item' => $dynamodb->attributes(array( 'id' => 1, // Primary (Hash) Key 'date' => time(), 'key1' => 'value1', 'key2' => 'value2', 'key3' => array('sub-value1', 'sub-value2'), )) ) ), array( 'PutRequest' => array( 'Item' => $dynamodb->attributes(array( 'id' => 2, // Primary (Hash) Key 'date' => time(), 'key1' => 'value3', 'key2' => 'value4', 'key3' => array('sub-value1', 'sub-value2'), )) ) ), array( 'PutRequest' => array( 'Item' => $dynamodb->attributes(array( 'id' => 3, // Primary (Hash) Key 'date' => time(), 'key1' => 'value5', 'key2' => 'value6', 'key3' => array('sub-value1', 'sub-value2'), )) ) ), ) ) )); var_dump($response->isOK()); sleep(1); #################################################################### # Scan the database // Scan the database for matches $response = $dynamodb->scan(array( 'TableName' => $table_name, 'AttributesToGet' => array('id', 'key1', 'key2', 'key3'), 'ScanFilter' => array( 'key1' => array( 'ComparisonOperator' => AmazonDynamoDB::CONDITION_EQUAL, 'AttributeValueList' => array( array( AmazonDynamoDB::TYPE_STRING => 'value5' ) ) ), ) )); // Did we get back what we expected? var_dump((integer) $response->body->Items->id->{AmazonDynamoDB::TYPE_NUMBER}); #################################################################### # Query the database $response = $dynamodb->query(array( 'TableName' => $table_name, 'HashKeyValue' => array( AmazonDynamoDB::TYPE_NUMBER => '1' ), 'RangeKeyCondition' => array( 'ComparisonOperator' => AmazonDynamoDB::CONDITION_GREATER_THAN_OR_EQUAL, 'AttributeValueList' => array( array(AmazonDynamoDB::TYPE_NUMBER => '0') ), ) )); // Did we get back what we expected? var_dump((string) $response->body->Items->key1->{AmazonDynamoDB::TYPE_STRING}); #################################################################### # Deleting the table $response = $dynamodb->delete_table(array( 'TableName' => $table_name )); var_dump($response->isOK()); // Sleep and poll until table is deleted do { sleep(1); $response = $dynamodb->describe_table(array( 'TableName' => $table_name )); } while ((integer) $response->status !== 400);Result:
bool(true) bool(true) int(3) string(6) "value1" bool(true)
Source
Method defined in services/dynamodb.class.php | Toggle source view (12 lines) | View on GitHub