使用 codeigniter 3 和 dynamodb 查询
Query with codeigniter 3 and dynamodb
如何在 Codeigniter 3 中使用 dynamodb 进行查询并另外包含索引?
在我的示例中,出现以下错误:
1 validation error detected: Value null at 'hashKeyValue' failed to
satisfy constraint: Member must not be null
这是我的例子:
function obtener($fecha_registro) {
$client = new AmazonDynamoDB();
$response = $client->query( array(
'TableName' => 'nom_table',
'KeyConditionExpression' => 'id_registro = :v_hash and fecha_registro = :v_range',
'ExpressionAttributeValues' => array (
':v_hash' => array('S' => '148537355319'),
':v_range' => array('S' => $fecha_registro)
)
));
print_r($response);
if ($response->status == '200'){
return $response->body->Items;
} else {
print_r($response);
}
}
您收到此错误的唯一原因是:
Amazon DynamoDB is not handling empty
or null
attributes.
Attribute values cannot be null.
AWS Developer Forum 也提出了同样的问题。
解法:
在将变量 $fecha_registro
传递给函数 obtener()
之前,
您需要检查传递的变量是 Non Empty
还是 Not Null
对于您的场景,只需在调用您的函数之前添加一个检查,如下所示:
if(isset($fecha_registro) && ($fecha_registro != '' || $fecha_registro != NULL)){
obtener($fecha_registro);
}
如何在 Codeigniter 3 中使用 dynamodb 进行查询并另外包含索引?
在我的示例中,出现以下错误:
1 validation error detected: Value null at 'hashKeyValue' failed to satisfy constraint: Member must not be null
这是我的例子:
function obtener($fecha_registro) {
$client = new AmazonDynamoDB();
$response = $client->query( array(
'TableName' => 'nom_table',
'KeyConditionExpression' => 'id_registro = :v_hash and fecha_registro = :v_range',
'ExpressionAttributeValues' => array (
':v_hash' => array('S' => '148537355319'),
':v_range' => array('S' => $fecha_registro)
)
));
print_r($response);
if ($response->status == '200'){
return $response->body->Items;
} else {
print_r($response);
}
}
您收到此错误的唯一原因是:
Amazon DynamoDB is not handling
empty
ornull
attributes.
Attribute values cannot be null.
AWS Developer Forum 也提出了同样的问题。
解法:
在将变量 $fecha_registro
传递给函数 obtener()
之前,
您需要检查传递的变量是 Non Empty
还是 Not Null
对于您的场景,只需在调用您的函数之前添加一个检查,如下所示:
if(isset($fecha_registro) && ($fecha_registro != '' || $fecha_registro != NULL)){
obtener($fecha_registro);
}