jeudi 21 mai 2015

AWS SDK for PHP DynamoDB PutItem for non null variables only

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'])
                 ),
                           ));
}




Aucun commentaire:

Enregistrer un commentaire