diff --git a/common.php b/common.php new file mode 100644 index 0000000..e2468cf --- /dev/null +++ b/common.php @@ -0,0 +1,16 @@ +'); + + + // Our config for DynamoDB client + $config = array( + // Replace with your desired region visit + // http://docs.aws.amazon.com/general/latest/gr/rande.html + // to get your regions. + 'region' => 'eu-west-1', + + // Now needs a version + 'version' => '2012-08-10', + ); diff --git a/createtables.php b/createtables.php index 096a4c1..a3cbfba 100644 --- a/createtables.php +++ b/createtables.php @@ -1,39 +1,40 @@ 'eu-west-1', // replace with your desired region visit http://docs.aws.amazon.com/general/latest/gr/rande.html to get your regions. - 'version' => '2012-08-10' // Now needs a version - )); - + + $client = DynamoDbClient::factory($config); + $tableNames = array(); - + $tableName = 'ProductCatalog'; - echo "Creating table $tableName..." . PHP_EOL; - + echo "Creating table $tableName..." . HTML_EOL; + $response = $client->createTable(array( 'TableName' => $tableName, 'AttributeDefinitions' => array( array( 'AttributeName' => 'Id', - 'AttributeType' => 'N' + 'AttributeType' => 'N' ) ), 'KeySchema' => array( array( 'AttributeName' => 'Id', - 'KeyType' => 'HASH' + 'KeyType' => 'HASH' ) ), 'ProvisionedThroughput' => array( @@ -42,16 +43,16 @@ ) )); $tableNames[] = $tableName; - + $tableName = 'Forum'; - echo "Creating table $tableName..." . PHP_EOL; - + echo "Creating table $tableName..." . HTML_EOL; + $response = $client->createTable(array( 'TableName' => $tableName, 'AttributeDefinitions' => array( array( 'AttributeName' => 'Name', - 'AttributeType' => 'S' + 'AttributeType' => 'S' ) ), 'KeySchema' => array( @@ -66,10 +67,10 @@ ) )); $tableNames[] = $tableName; - + $tableName = 'Thread'; - echo "Creating table $tableName..." . PHP_EOL; - + echo "Creating table $tableName..." . HTML_EOL; + $response = $client->createTable(array( 'TableName' => $tableName, 'AttributeDefinitions' => array( @@ -98,24 +99,24 @@ ) )); $tableNames[] = $tableName; - + $tableName = 'Reply'; - echo "Creating table $tableName..." . PHP_EOL; - + echo "Creating table $tableName..." . HTML_EOL; + $response = $client->createTable(array( 'TableName' => $tableName, 'AttributeDefinitions' => array( array( 'AttributeName' => 'Id', - 'AttributeType' => 'S' + 'AttributeType' => 'S' ), array( 'AttributeName' => 'ReplyDateTime', - 'AttributeType' => 'S' + 'AttributeType' => 'S' ), array( 'AttributeName' => 'PostedBy', - 'AttributeType' => 'S' + 'AttributeType' => 'S' ) ), 'LocalSecondaryIndexes' => array( @@ -139,7 +140,7 @@ 'KeySchema' => array( array( 'AttributeName' => 'Id', - 'KeyType' => 'HASH' + 'KeyType' => 'HASH' ), array( 'AttributeName' => 'ReplyDateTime', @@ -152,9 +153,9 @@ ) )); $tableNames[] = $tableName; - + foreach($tableNames as $tableName) { - echo "Waiting for table $tableName to be created." . PHP_EOL; + echo "Waiting for table $tableName to be created." . HTML_EOL; $client->waitUntil('TableExists', array('TableName' => $tableName)); // Changed from v2 - echo "Table $tableName has been created." . PHP_EOL; + echo "Table $tableName has been created." . HTML_EOL; } diff --git a/uploaddata.php b/uploaddata.php index 4f4327d..360fc84 100644 --- a/uploaddata.php +++ b/uploaddata.php @@ -1,4 +1,6 @@ 'eu-west-1', // replace with your desired region - 'version' => '2012-08-10' // Now needs a version - )); + $client = DynamoDbClient::factory($config); # Setup some local variables for dates @@ -26,7 +25,7 @@ $twentyOneDaysAgo = date('Y-m-d H:i:s', strtotime('-21 days')); $tableName = 'ProductCatalog'; - echo "Adding data to the $tableName table..." . PHP_EOL; + echo "Adding data to the $tableName table..." . HTML_EOL; $response = $client->batchWriteItem(array( 'RequestItems' => array( @@ -155,12 +154,12 @@ ), )); - echo "done." . PHP_EOL; + echo "done." . HTML_EOL; $tableName = 'Forum'; - echo "Adding data to the $tableName table..." . PHP_EOL; + echo "Adding data to the $tableName table..." . HTML_EOL; $response = $client->batchWriteItem(array( 'RequestItems' => array( @@ -189,11 +188,11 @@ ) )); - echo "done." . PHP_EOL; + echo "done." . HTML_EOL; $tableName = 'Reply'; - echo "Adding data to the $tableName table..." . PHP_EOL; + echo "Adding data to the $tableName table..." . HTML_EOL; $response = $client->batchWriteItem(array( 'RequestItems' => array( @@ -242,4 +241,4 @@ ) )); - echo "done." . PHP_EOL; + echo "done." . HTML_EOL;