Use the Tablestore PHP SDK to read data from multiple tables in a single batch request.
Usage notes
A single batch read operation can retrieve up to 100 rows of data.
Prerequisites
Method
public function batchGetRow(array $request)Examples
Read two rows with primary key values row1 and row2 from the test_table table:
$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.";
}Configure batch read parameters as needed:
Read data from multiple tables. Batch read operations support retrieving data from multiple tables simultaneously. Specify a MultiRowQueryCriteria for each table.
$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 ) );Set a time range for the data versions to retrieve. Only data within the specified time range is returned.
// 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) );Specify the attribute columns to retrieve.
$table['columns_to_get'] = array('col2');