doutang2017 2015-05-21 15:01
浏览 100

适用于PHP DynamoDB的AWS SDK仅适用于非空变量的PutItem

I'm inserting variables into the AWS DynamoDB from an array $dbf[$a]['variable1'], $dbf[$a]['variable2'], $dbf[$a]['variable3'] ...

for some $a, only 'variable1' and 'variable2' are set, and for other $a, all 'variable#' are set.

The below code won't work because Null or non set variables aren't allowed.

Is there a way in the loop to only attempt to "PutItem" for variables that are set?

foreach($dbf as $day)
{
$result = $client->PutItem(array(
    'TableName' => 'AWIS',
    'Item' => array(
        'id' => array('S' =>  $day['id']),
        'date'=> array('S' => $day['date']),
       'max'=> array('N' => $day['max']),
       'min'=> array('N' => $day['min']),
       'pre'=> array('N' => $day['pre']),
       'max_soil_temp'=> array('N' => $day['max_soil_temp']),
       'min_soil_temp'=> array('N' => $day['min_soil_temp']),
       'evap'=> array('N' => $day['evap']),
       'veg_wetting'=> array('N' => $day['veg_wetting']),
       'solar_rad'=> array('N' => $day['solar_rad']),
       'ob_temp'=> array('N' => $day['ob_temp']),
       'adj_min'=> array('N' => $day['adj_min']),
       'chill_hours'=> array('N' => $day['chill_hours'])
                 ),
                           ));
}
  • 写回答

1条回答 默认 最新

  • drgc9632 2015-05-22 06:06
    关注

    You can potentially do like:

    if ($yourValue) {
            $params['yourKey'] = array(
                'Action' => 'PUT',
                'Value' => array(
                    Type::STRING => $yourValue
                )
            );
        }
    
    $response = $Client->updateItem(array(
                "TableName" => "tableName",
                "Key" => array(
                    "Id" => array(
                        Type::STRING => $Id
                    )
                ),
                "AttributeUpdates" => $params
                    )
            ); 
    

    Set all the params that are available in loop and will update only those values which is available

    Hope that helps

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题