需要一个完整的例子DynamoDB用PHP例子、完整、PHP、DynamoDB

由网友(浅若清风)分享简介:我想在PHP编写的服务,其中 - I want to write service in php where -1)DynamoDB将表t两列键和val 1) DynamoDB will have table t with two columns key and val2),我会检查,如果一些关键存在于表T与否。...

我想在PHP编写的服务,其中 -

I want to write service in php where -

1)DynamoDB将表t两列键和val

1) DynamoDB will have table t with two columns key and val

2),我会检查,如果一些关键存在于表T与否。

2) I will check if some key exists in table t or not.

3)如果不存在读取数据。如果不存在表t插入新的键值

3) If exist read data .. if don't exist insert new key-value in table t

我检查了一些链接 的http://docs.aws.amazon.com/AWSSDKforPHP/latest/index.html#m=AmazonDynamoDB/put_item http://docs.aws.amazon.com /aws-sdk-php/guide/latest/quick-start.html

I was checking some links http://docs.aws.amazon.com/AWSSDKforPHP/latest/index.html#m=AmazonDynamoDB/put_item http://docs.aws.amazon.com/aws-sdk-php/guide/latest/quick-start.html

哪一个跟着?

也可以有人给我简单的例子和​​准确的语法。

Also can someone give me quick example and exact syntax.

在此先感谢。

推荐答案

完整的演练位于这里 - RazrPHP 。它为您提供了一个逐步安装过程中的一步纲要凭据,并配备了一个易于使用的添加到 PHP SDK的 AWS

The full walkthrough is located HERE - RazrPHP. It gives you a step by step outline of the setup process for credentials and comes with a easy to use add on to the PHP SDK for AWS

1 转到AWS,让您的 PUBLIC_KEY 和 PRIVATE_KEY

1. Go to AWS and get your PUBLIC_KEY and PRIVATE_KEY 在AWS确实有教程,这这里和这里

2 打开终端

3 如果您尚未创建您的凭据然而,在终端的新的一页,类型:

3. If you haven't created your credentials yet, in Terminal's fresh page, type in:

nano ~/.aws/credentials

纳米功能页面将打开。你会看到 GNU纳米2.0.6 ... 上方。

The nano function page will open up. You will see GNU nano 2.0.6... at the top.

4 在纳米页,类型:

[default]
aws_access_key_id = public_key_ABCDEFGHIJKLMNOPQRSTUVWXYZ
aws_secret_access_key = private_key_s0m3_CR42Y_l3tt3rS_i5y0ur53cr3tK3y

5。一旦你键入了出去,撞在控制+ X (是......控制,而不是命令)。

5. Once you've typed it out, hit CONTROL + X (Yes...Control, not Command).

1 把 AWS_SDK_PHP 在空文件夹

2 在使用SDK文件的顶部(的index.php 或其他),放于: 1. Put the AWS_SDK_PHP in an empty folder 一个好用的dynamodb可视化工具

2. At the top of the file using the SDK (index.php or whatever), put in:

require 'aws/aws-autoloader.php';
date_default_timezone_set('America/New_York');

use AwsDynamoDbDynamoDbClient;

$client = new DynamoDbClient([
    'profile' => 'default',
    'region'  => 'us-east-1',
    'version' => 'latest'
]);

数据类型 取值 =字符串 N =号 B =二进制 Data Types S = String N = Number B = Binary

的基本方法

描述表

$result = $client->describeTable(array(
    'TableName' => '[Table_Name]'
));

echo $result;

将项目

$response = $client->putItem(array(
    'TableName' => '[Table_Name]', 
    'Item' => array(
        '[Hash_Name]'   => array('S' => '[Hash_Value]'),
        '[Range_Name]'  => array('S' => '[Range_Value]')
    )
));

//Echoing the response is only good to check if it was successful. Status: 200 = Success
echo $response;

获取项目

$response = $client->getItem(array(
    'TableName' => '[Table_Name]',
    'Key' => array(
        '[Hash_Name]'  => array('S' => '[Hash_Value]'),
        '[Range_Name]' => array('S' => '[Range_Value]')
    )
));

echo $response;

删除项目

$response = $client->deleteItem(array(
    'TableName' => '[Table_Name]',
    'Key' => array(
        '[Hash_Name]'  => array('S' => '[Hash_Value]'),
        '[Range_Name]' => array('S' => '[Range_Value]')
    )
));
//Echoing the response is only good to check if it was successful. Status: 200 = Success
echo $response;

查询项目

$response = $client->query(array(
    'TableName' => '[Table_Name]',
    'KeyConditionExpression' => '[Hash_Name] = :v_hash and [Range_Name] = :v_range',
    'ExpressionAttributeValues' =>  array (
        ':v_hash'  => array('S' => '[Hash_Value]'),
        ':v_range' => array('S' => '[Range_Value]')
    )
));

echo $response;

希望这有助于。

亚马逊dynamodb < A HREF =/问题/标记/ AWS级=后标签称号=显示问题标记AWS相对=标签> AWS 的 AWS-设置

阅读全文

相关推荐

最新文章