Skip to content
This repository was archived by the owner on Aug 4, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

// Custom html end of line constant (Leave it as it is)
define('HTML_EOL', '<br />');


// 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',
);
65 changes: 33 additions & 32 deletions createtables.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
<?php
//Code is provided by AWS and available here; http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/AppendixSampleDataCodePHP.html

// Load common stuff
require_once('common.php');

// Code is provided by AWS and available here;
// http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/AppendixSampleDataCodePHP.html

// Date now needs to be set, which I guess is a good thing!
date_default_timezone_set('Europe/London');

// Find out what the issues are:
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

require '/var/www/html/vendor/autoload.php';
use Aws\DynamoDb\DynamoDbClient;

$client = DynamoDbClient::factory(array(
'region' => '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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -139,7 +140,7 @@
'KeySchema' => array(
array(
'AttributeName' => 'Id',
'KeyType' => 'HASH'
'KeyType' => 'HASH'
),
array(
'AttributeName' => 'ReplyDateTime',
Expand All @@ -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;
}
19 changes: 9 additions & 10 deletions uploaddata.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
// Load common stuff
require_once('common.php');

// Date now needs to be set, which I guess is a good thing!
date_default_timezone_set('Europe/London');
Expand All @@ -11,10 +13,7 @@
require '/var/www/html/vendor/autoload.php';
use Aws\DynamoDb\DynamoDbClient;

$client = DynamoDbClient::factory(array(
'region' => '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

Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -242,4 +241,4 @@
)
));

echo "done." . PHP_EOL;
echo "done." . HTML_EOL;