php - DynamoDB 与 PHP,update_item 错误

标签 php amazon-web-services amazon-dynamodb

我正在尝试使用 PHP SDK 更新我的 DynamoDB 表中的表。这是错误:

com.amazon.coral.service#SerializationException 在不希望的地方找到列表的开始

我猜我的数组格式有问题。我正在使用这个 documentation以供引用。

我发送的数组:

array(3) {
  ["TableName"]=>
  string(7) "teacher"
  ["Key"]=>
  array(1) {
    ["HashKeyElement"]=>
    array(1) {
      ["S"]=>
      string(36) "97770A6A-EF06-AF4A-3E30-87DAC0237F6D"
    }
  }
  ["AttributeUpdates"]=>
  array(1) {
    [0]=>
    array(2) {
      ["population"]=>
      array(1) {
        ["Action"]=>
        string(3) "ADD"
      }
      ["Value"]=>
      array(1) {
        ["SS"]=>
        array(1) {
          [0]=>
          string(36) "97770A6A-EF06-AF4A-3E30-87DAC0237F6D"
        }
      }
    }
  }
}

最佳答案

AttributeUpdates 中的“人口”在数组中的位置不正确。它应该是元素的键而不是元素本身。 “Value”和“Action”都是数组元素的一部分:结构应该是:

array(3) {
  ["TableName"]=>
  string(7) "teacher"
  ["Key"]=>
  array(1) {
    ["HashKeyElement"]=>
    array(1) {
      ["S"]=>
      string(36) "97770A6A-EF06-AF4A-3E30-87DAC0237F6D"
    }
  }
  ["AttributeUpdates"]=>
  array(1) {
    ["population"]=>
    array(1) {
      ["Value"]=>
      array(2) {
        ["SS"]=>
        array(1) {
          [0]=>
          string(36) "97770A6A-EF06-AF4A-3E30-87DAC0237F6D"
        }
        ["Action"]=>
        string(3) "ADD"
      }
    }
  }
}

来源:

$updateOptions = array(
  'TableName'    => 'teacher',
  'Key'          => array(
      'HashKeyElement'  => array('S' => '97770A6A-EF06-AF4A-3E30-87DAC0237F6D'),
  ),
  'AttributeUpdates' => array(
      'population'    => array('Value' => array('SS' => array('97770A6A-EF06-AF4A-3E30-87DAC0237F6D'), 'Action' => 'ADD')),
  )
);

关于php - DynamoDB 与 PHP,update_item 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10660621/

相关文章:

php-登录验证不起作用

php - 从准备好的语句中获取文本(PHP、PDO)

mysql - 调整具有WriteIOPS不稳定性的MySQL RDS

node.js - SignatureDoesNotMatch $cordovaFileTransfer

java - 根据 id 从 DynamoDB 检索项目并转换该项目

database - 在什么情况下你会在 DynamoDB 上使用 Simple Hash Keys?

PHP MySQLi 权限被拒绝但从 MySQL CLI 工作

php - Woocommerce 自定义支付网关重定向

amazon-web-services - 使用 cloudformation 安装 Aurora Postgresql

node.js - NodeJS 中用于 API 的 stub DynamoDB