The above example will not work when u will have some null value to your array..
suppose i am retrieving the value from some form
so i have to do the work like this ..
if (!empty($_POST['update'])) {
$id = intval($_POST['id']);
$name = strval($_POST['name']);
$type = strval($_POST['type']);
$nationality = strval($_POST['nationality']);
$price = intval($_POST['price']);
if(!empty($price))
{
$value['PlayerPrice']=array(
"Value" => array('N' => $price)
);
}
if(!empty($type))
{
$value['PlayerType']=array(
"Value" => array('S' => $type)
);
}
if(!empty($nationality))
{
$value['PlayerNationality']=array(
"Value" => array('S' => $nationality)
);
}
print_r($value);
$response = $client->updateItem(array(
"TableName" => $newtablename,
"Key" => array(
"PlayerId" => array('N' => $id),
"PlayerName" => array('S' => $name)
),
"AttributeUpdates" =>$value,
"ReturnValues" => \Aws\DynamoDb\Enum\ReturnValue::ALL_NEW
));
echo "Record Updated";
}
so even if there is a null value to any attribute it will not give error because if you are passing any null value to table it will not update and fire an error
That is the most important thing to take care
one more thing i have PlayerId as HASH key and PlayerName as RANGE key
if we are updating with different value in any of this field it will create anew item as they both make composite key