Was this page helpful?
Using the “PHP AWS SDK” we can easily connect our project on any ScyllaDB instance (Local/Cloud) that is configured with Alternator flag.
Create a new folder
If you’re starting a new project, make sure to require the SDK package in your application.
composer require aws/aws-sdk-php
You can instantiate a new DynamoDB Client by using:
use Aws\DynamoDb\DynamoDbClient;
$alternatorClient = new DynamoDbClient([
'endpoint' => 'http://localhost:8000', // ScyllaDB Alternator LocalHost URL
'credentials' => ['key' => 'None', 'secret' => 'None'],
'region' => 'None'
]);
Here’s the DynamoDB queries used on this project so far:
use Aws\DynamoDb\DynamoDbClient;
$alternatorClient = new DynamoDbClient([
'endpoint' => 'http://localhost:8000', // ScyllaDB Alternator LocalHost URL
'credentials' => ['key' => 'None', 'secret' => 'None'],
'region' => 'None'
]);
$alternatorClient->createTable(['TableName' => 'songs',
'KeySchema' => [
['AttributeName' => 'id', 'KeyType' => 'HASH'],
['AttributeName' => 'created_at', 'KeyType' => 'RANGE'],
],
'AttributeDefinitions' => [
['AttributeName' => 'id', 'AttributeType' => 'S'],
['AttributeName' => 'created_at', 'AttributeType' => 'S'],
['AttributeName' => 'title', 'AttributeType' => 'S'],
['AttributeName' => 'artist', 'AttributeType' => 'S'],
['AttributeName' => 'album', 'AttributeType' => 'S'],
],
'ProvisionedThroughput' => [
'ReadCapacityUnits' => 10,
'WriteCapacityUnits' => 10
]
]);
use Aws\DynamoDb\DynamoDbClient;
$alternatorClient = new DynamoDbClient([
'endpoint' => 'http://localhost:8000', // ScyllaDB Alternator LocalHost URL
'credentials' => ['key' => 'None', 'secret' => 'None'],
'region' => 'None'
]);
$alternatorClient->putItem('PutRequest' => [
'TableName' => 'songs',
'Item' => [
'id' => ['S' => 'string'],
'created_at' => ['S' => 'string'],
'title' => ['S' => 'string'],
'album' => ['S' => 'string'],
'artist' => ['S' => 'string'],
]
]);
use Aws\DynamoDb\DynamoDbClient;
use Aws\DynamoDb\Marshaler;
$marshaler = new Marshaler();
$alternatorClient = new DynamoDbClient([
'endpoint' => 'http://localhost:8000', // ScyllaDB Alternator LocalHost URL
'credentials' => ['key' => 'None', 'secret' => 'None'],
'region' => 'None'
]);
$results = $client->scan(['TableName' => 'songs']);
foreach ($results['Items'] as $item) {
$parsedItem = $marshaler->unmarshalItem($item);
var_dump($parsedItem['title'])
}
use Aws\DynamoDb\DynamoDbClient;
use Aws\DynamoDb\Marshaler;
$marshaler = new Marshaler();
$alternatorClient = new DynamoDbClient([
'endpoint' => 'http://localhost:8000', // ScyllaDB Alternator LocalHost URL
'credentials' => ['key' => 'None', 'secret' => 'None'],
'region' => 'None'
]);
$client->deleteItem([
'TableName' => 'songs',
'Key' => [
'id' => ['S' => 'some-uuid-here'],
'created_at' => ['S' => 'Y-m-d H:i:s'],
],
]);