Read a single row from a Tablestore table by primary key, using the PHP SDK.
Usage notes
Provide the complete primary key value when reading data, including the value for the auto-increment primary key column.
Before you begin
Method description
public function getRow(array $request)
Sample code
The following example reads a single row with the primary key value row1.
$request = array (
'table_name' => 'test_table',
// Construct primary key
'primary_key' => array (
array ('id', 'row1')
),
'max_versions' => 1
);
try {
// Call the getRow method to read row data
$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.";
}
-
Set a version range to return only data within that range.
// Set the query data version range to one day before the current time $request['time_range'] = array ( 'start_time' => intval(microtime(true) * 1000) - 86400 * 1000, 'end_time' => intval(microtime(true) * 1000) ); -
Specify the attribute columns to read.
$request['columns_to_get'] = array('col2');