本文介绍如何通过 PHP SDK 读取表格存储数据表的单行数据。
注意事项
读取数据时需要提供包含自增主键列值在内的完整主键值。
前提条件
方法说明
public function getRow(array $request)示例代码
以下示例代码读取了主键值为 row1 的单行数据。
$request = array (
'table_name' => 'test_table',
// 构造主键
'primary_key' => array (
array ('id', 'row1')
),
'max_versions' => 1
);
try {
// 调用 getRow 方法读取行数据
$response = $client->getRow ($request);
echo "* Read CU Cost: " . $response['consumed']['capacity_unit']['read'] . "\n";
echo "* Write CU Cost: " . $response['consumed']['capacity_unit']['write'] . "\n";
echo "* Row Data: " . "\n";
echo "Primary Key: ". json_encode($response['primary_key']) . "\n";
echo "Attribute Columns: ". json_encode($response['attribute_columns']) . "\n";
} catch (Exception $e){
echo "Get Row failed.";
}设置读取的数据版本范围,结果只返回版本范围内的数据。
// 设置查询的数据版本范围为当前时间往前一天 $request['time_range'] = array ( 'start_time' => intval(microtime(true) * 1000) - 86400 * 1000, 'end_time' => intval(microtime(true) * 1000) );指定读取的属性列。
$request['columns_to_get'] = array('col2');
相关文档
该文章对您有帮助吗?