Baca satu baris dari tabel Tablestore berdasarkan kunci primer menggunakan PHP SDK.
Catatan penggunaan
Berikan nilai lengkap kunci primer saat membaca data, termasuk nilai untuk kolom kunci utama auto-increment.
Sebelum memulai
Deskripsi metode
public function getRow(array $request)
Kode contoh
Contoh berikut membaca satu baris dengan nilai kunci primer 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.";
}
-
Tentukan rentang versi untuk hanya mengembalikan data dalam rentang tersebut.
// 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) ); -
Tentukan kolom atribut yang akan dibaca.
$request['columns_to_get'] = array('col2');