Tablestore PHP SDK kullanarak tek bir toplu istekle birden çok tablodan veri okuyun.
Kullanım notları
Tek bir toplu okuma işlemi en fazla 100 satır veri alabilir.
Ön koşullar
Yöntem
public function batchGetRow(array $request)
Örnekler
test_table tablosundan birincil anahtar değerleri row1 ve row2 olan iki satırı okuyun:
$table = array (
'table_name' => 'test_table',
'max_versions' => 1,
'primary_keys' => array (
array ( array('id', 'row1') ),
array ( array('id', 'row2') )
)
);
$request = array (
'tables' => array (
$table
)
);
try {
// Call the batchGetRow method to read row data.
$response = $client->batchGetRow ($request);
// Process the response.
foreach ($response['tables'] as $tableGroup) {
echo "* Table: " . $tableGroup['table_name'] . "\n";
foreach ($tableGroup['rows'] as $row) {
if ($row['is_ok']) {
if ($row['primary_key'] != null) {
echo "Succeeded Row: " . json_encode($row['primary_key']) . json_encode($row['attribute_columns']) . "\n";
} else {
echo "Succeeded Row: This row is not exist." . "\n";
}
} else {
echo "Failed Row: " . $row['error']['code'] . '. ' . $row['error']['message'] . "\n";
}
}
}
} catch (Exception $e){
echo "Batch get row failed.";
}
Toplu okuma parametrelerini ihtiyaca göre yapılandırın:
-
Her tablo için ayrı bir yapılandırma belirterek birden çok tablodan veri okuyun.
$table1 = array ( 'table_name' => 'orders_small', 'max_versions' => 1, 'primary_keys' => array ( array ( array('order_id', '90fb478c-1360-11f0-a34d-00163e30a2a9') ) ) ); $request = array ( 'tables' => array ( $table, $table1 ) ); -
Alınacak veri sürümleri için bir zaman aralığı ayarlayın. Yalnızca belirtilen zaman aralığındaki veriler döndürülür.
// Set the time range for the query to the last 24 hours. $table['time_range'] = array ( 'start_time' => intval(microtime(true) * 1000) - 86400 * 1000, 'end_time' => intval(microtime(true) * 1000) ); -
Alınacak nitelik sütunlarını belirtin.
$table['columns_to_get'] = array('col2');