<small id='Os3X8'></small><noframes id='Os3X8'>

    1. <i id='Os3X8'><tr id='Os3X8'><dt id='Os3X8'><q id='Os3X8'><span id='Os3X8'><b id='Os3X8'><form id='Os3X8'><ins id='Os3X8'></ins><ul id='Os3X8'></ul><sub id='Os3X8'></sub></form><legend id='Os3X8'></legend><bdo id='Os3X8'><pre id='Os3X8'><center id='Os3X8'></center></pre></bdo></b><th id='Os3X8'></th></span></q></dt></tr></i><div id='Os3X8'><tfoot id='Os3X8'></tfoot><dl id='Os3X8'><fieldset id='Os3X8'></fieldset></dl></div>
      <tfoot id='Os3X8'></tfoot>

        <bdo id='Os3X8'></bdo><ul id='Os3X8'></ul>
      1. <legend id='Os3X8'><style id='Os3X8'><dir id='Os3X8'><q id='Os3X8'></q></dir></style></legend>
      2. 使用 PHP AWS SDK 在 DynamoDB 中存储 JSON 文档

        时间:2024-05-10

      3. <tfoot id='Q3Jqg'></tfoot>
          <bdo id='Q3Jqg'></bdo><ul id='Q3Jqg'></ul>

            <small id='Q3Jqg'></small><noframes id='Q3Jqg'>

              <tbody id='Q3Jqg'></tbody>
            <legend id='Q3Jqg'><style id='Q3Jqg'><dir id='Q3Jqg'><q id='Q3Jqg'></q></dir></style></legend>

                • <i id='Q3Jqg'><tr id='Q3Jqg'><dt id='Q3Jqg'><q id='Q3Jqg'><span id='Q3Jqg'><b id='Q3Jqg'><form id='Q3Jqg'><ins id='Q3Jqg'></ins><ul id='Q3Jqg'></ul><sub id='Q3Jqg'></sub></form><legend id='Q3Jqg'></legend><bdo id='Q3Jqg'><pre id='Q3Jqg'><center id='Q3Jqg'></center></pre></bdo></b><th id='Q3Jqg'></th></span></q></dt></tr></i><div id='Q3Jqg'><tfoot id='Q3Jqg'></tfoot><dl id='Q3Jqg'><fieldset id='Q3Jqg'></fieldset></dl></div>
                  本文介绍了使用 PHP AWS SDK 在 DynamoDB 中存储 JSON 文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我阅读了 文档其中有 PHP 示例使用 AWS 开发工具包在 dynamicDB 表中插入数据.但是,这是针对表格数据的.我正在尝试插入 JSON 数据,即键值对,其中 value 是 JSON 文档.我该怎么做?

                  I read the documentation where there are PHP examples to insert data in a dynamicDB table using AWS SDK. However this is for tabular data. I am trying to insert JSON data i.e. Key Value pair where value is a JSON document. How do I do that ?

                  我尝试了文档中的以下代码,但除非 value 是数组,否则它不起作用.

                  I tried the following code from the doc but it does not work unless value is an array.

                  <?php
                  
                  require '/home/ubuntu/vendor/autoload.php';
                  
                  use AwsDynamoDbDynamoDbClient;
                  
                  $client = DynamoDbClient::factory(array(
                      'profile' => 'default',
                      'region'  => 'ap-southeast-1',
                      'version' => '2012-08-10'
                  ));
                  
                  $id = "key";
                  $value = '{"subKey":"value"}'
                  
                  
                  $result = $client->putItem(array(
                      'TableName' => 'myTable',
                      'Item' => array(
                          'key'  => $value
                      )
                  ));
                  

                  它给了我以下错误

                  Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Found 2 errors while validating the input provided for the PutItem operation: [Item][key] must be an associative array. Found string(1) "2" [Item][userId] must be an associative array. Found string(18) "{"subKey":"value"}"' in /home/ubuntu/vendor/aws/aws-sdk-php/src/Api/Validator.php:38 Stack trace: #0 /home/ubuntu/vendor/aws/aws-sdk-php/src/Middleware.php(78): AwsApiValidator->validate('PutItem', Object(AwsApiStructureShape), Array) #1 /home/ubuntu/vendor/aws/aws-sdk-php/src/AwsClient.php(208): AwsMiddleware::Aws{closure}(Object(AwsCommand)) #2 /home/ubuntu/vendor/aws/aws-sdk-php/src/AwsClient.php(202): AwsAwsClient->executeAsync(Object(AwsCommand)) #3 /home/ubuntu/vendor/aws/aws-sdk-php/src/AwsClient.php(167): AwsAwsClient->execute(Object(AwsCommand)) #4 /var/www/html/dynamoDB.php(25): AwsAwsClient->__call('putItem', Array) #5 /var/www/html/dynamoDB.php(25): AwsDynamoDbDynamoDbClient->putItem(Array) #6 {main} thrown in /home/ubuntu/vendor/aws/aws-sdk-php/src/Api/Validator.php on line 38
                  

                  推荐答案

                  DynamoDB 要求您在请求中指定 AttributeValue 类型.这是来自 https://docs 的示例.aws.amazon.com/aws-sdk-php/v2/guide/service-dynamodb.html:

                  DynamoDB requires you specify the AttributeValue types with the request. Here is the example from https://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-dynamodb.html:

                  $result = $client->putItem(array(
                      'TableName' => 'errors',
                      'Item' => array(
                          'id'      => array('N' => '1201'),
                          'time'    => array('N' => $time),
                          'error'   => array('S' => 'Executive overflow'),
                          'message' => array('S' => 'no vacant areas')
                      )
                  ));
                  

                  对于您的示例,请尝试添加 DynamoDB 类型:

                  For your example try adding DynamoDB types:

                  $result = $client->putItem(array(
                      'TableName' => 'myTable',
                      'Item' => array(
                          'key'  => array('S' => $value)
                      )
                  ));
                  

                  这里的S"可以替换为N"、B"、SS"、NS"、BS"、M"、L"或BOOL":https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html#DataModel.DataTypes

                  Where 'S' could be replaced with 'N', 'B', 'SS', 'NS', 'BS', 'M', 'L', or 'BOOL' as defined here: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html#DataModel.DataTypes

                  这篇关于使用 PHP AWS SDK 在 DynamoDB 中存储 JSON 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何检查dynamodb中的字符串集中是否存在字符串 下一篇:使用多个嵌套 JSON 键 (PHP) 进行 DynamoDB 扫描

                  相关文章

                  <i id='tvpDd'><tr id='tvpDd'><dt id='tvpDd'><q id='tvpDd'><span id='tvpDd'><b id='tvpDd'><form id='tvpDd'><ins id='tvpDd'></ins><ul id='tvpDd'></ul><sub id='tvpDd'></sub></form><legend id='tvpDd'></legend><bdo id='tvpDd'><pre id='tvpDd'><center id='tvpDd'></center></pre></bdo></b><th id='tvpDd'></th></span></q></dt></tr></i><div id='tvpDd'><tfoot id='tvpDd'></tfoot><dl id='tvpDd'><fieldset id='tvpDd'></fieldset></dl></div>
                • <legend id='tvpDd'><style id='tvpDd'><dir id='tvpDd'><q id='tvpDd'></q></dir></style></legend>

                    <small id='tvpDd'></small><noframes id='tvpDd'>

                    <tfoot id='tvpDd'></tfoot>

                        <bdo id='tvpDd'></bdo><ul id='tvpDd'></ul>