需要一个完整的例子DynamoDB用PHP [英] Need a complete example for DynamoDB with php
问题描述
我想在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确实有教程,这这里和<一href="http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-key-pairs.html#having-ec2-create-your-key-pair"相对=nofollow>这里
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 seeGNU 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
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 Aws\DynamoDb\DynamoDbClient;
$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 的 PHP 的 SDK 的 dynamodb 查询问题 < A HREF =/问题/标记/ AWS-设置类=后标签称号=显示标记的问题,AWS-设置'相对=标签> AWS-设置
这篇关于需要一个完整的例子DynamoDB用PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!