gpt4 book ai didi

php - 使用 codeigniter 3 和 dynamodb 进行查询

转载 作者:行者123 更新时间:2023-12-01 05:23:02 24 4
gpt4 key购买 nike

如何使用 dynamodb 在 Codeigniter 3 中进行查询并添加索引?

在我的示例中,我收到以下错误:

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.

根据DynamoDB Documentation :

Attribute values cannot be null.

AWS Developer Forum 处提出了同样的问题还有。

解决方案:

在将变量 $fecha_registro 传递给函数 obtener() 之前,您需要检查传递的变量是否为 Non EmptyNot Null

对于您的场景,只需在调用函数之前添加检查,如下所示:

if(isset($fecha_registro) && ($fecha_registro != '' || $fecha_registro != NULL)){
obtener($fecha_registro);
}

关于php - 使用 codeigniter 3 和 dynamodb 进行查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41863551/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com