ScyllaDB University Live | Free Virtual Training Event
Learn more
ScyllaDB Documentation Logo Documentation
  • Server
  • Cloud
  • Tools
    • ScyllaDB Manager
    • ScyllaDB Monitoring Stack
    • ScyllaDB Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
  • Resources
    • ScyllaDB University
    • Community Forum
    • Tutorials
Download
ScyllaDB Docs ScyllaDB Cloud Getting Started Documentation ScyllaDB Alternator: PHP Example

ScyllaDB Alternator: PHP Example¶

Using the “PHP AWS SDK” we can easily connect our project on any ScyllaDB instance (Local/Cloud) that is configured with Alternator flag.

Quick Start¶

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'
]);

Queries¶

Here’s the DynamoDB queries used on this project so far:

Creating a Table¶

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
    ]
]);

Adding Items¶

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'],
    ]
]);

Listing Items¶

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'])
}

Deleting Items¶

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'],
    ],
]);

Was this page helpful?

PREVIOUS
Getting Started with ScyllaDB Cloud + DynamoDB Compatible API: A sample Media Player App with Alternator
NEXT
ScyllaDB Alternator: Python Example
  • Create an issue
  • Edit this page

On this page

  • ScyllaDB Alternator: PHP Example
    • Quick Start
    • Queries
      • Creating a Table
      • Adding Items
      • Listing Items
      • Deleting Items
ScyllaDB Cloud Getting Started Documentation
  • Getting Started
  • Design and Data Model
  • Build with JavaScript
  • Build with Java
  • Build with Elixir
  • Build with Python
  • Build with Ruby
  • Build with Rust
  • Build with Csharp
  • Build with Golang
  • Getting Started GitHub Repository
  • Alternator: Getting Started
  • Alternator: Build with PHP
  • Alternator: Build with Python
  • Getting Started GitHub Repository
Docs Tutorials University Contact Us About Us
© 2025, ScyllaDB. All rights reserved. | Terms of Service | Privacy Policy | ScyllaDB, and ScyllaDB Cloud, are registered trademarks of ScyllaDB, Inc.
Last updated on 05 May 2025.
Powered by Sphinx 7.4.7 & ScyllaDB Theme 1.8.6