<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 文档

        Storing JSON document in DynamoDB using PHP AWS SDK(使用 PHP AWS SDK 在 DynamoDB 中存储 JSON 文档)

      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 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <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>
                          <tbody id='tvpDd'></tbody>

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