This topic describes how to query detailed information about a table by using the PHP SDK.
Prerequisites
A client is initialized. For more information, see Initialize a Tablestore client.
Method description
public function describeTable(array $request)Sample code
The following sample code demonstrates how to query detailed information about the test_table table.
try{
$response = $client->describeTable(array (
'table_name' => 'test_table',
));
// Table schema information.
echo "* Table name: " . $response['table_meta']['table_name'] . "\n";
echo "* Primary key information \n";
foreach ($response['table_meta']['primary_key_schema'] as $primaryKey) {
echo "{$primaryKey[0]}: {$primaryKey[1]} \n";
}
echo "* Predefined column information \n";
foreach ($response['table_meta']['defined_column'] as $definedColumn) {
echo "{$definedColumn[0]}: {$definedColumn[1]} \n";
}
// Table configuration information
echo "* Table configuration information \n";
echo "Time to live: " . $response['table_options']['time_to_live'] . "\n";
echo "Max versions: " . $response['table_options']['max_versions'] . "\n";
echo "Max version offset: " . $response['table_options']['deviation_cell_version_in_sec'] . "\n";
echo "Whether to allow updates: " . ($response['table_options']['allow_update'] ? 'true' : "false") . "\n";
// Table Stream information
echo "* Whether to enable Stream: " . ($response['stream_details']['enable_stream'] ? 'true' : "false") . "\n";
if($response['stream_details']['enable_stream']){
echo "Stream expiration time: " . $response['stream_details']['expiration_time'] . "\n";
}
// Reserved read/write throughput of the table
echo "* Reserved read/write throughput \n";
echo "Reserved read throughput: " . $response['capacity_unit_details']['capacity_unit']['read'] . "\n";
echo "Reserved write throughput: " . $response['capacity_unit_details']['capacity_unit']['write'] . "\n";
// Secondary index information
foreach ($response['index_metas'] as $indexMeta) {
echo "* Secondary index name: " . $indexMeta['name'] . "\n";
echo "Primary key columns: [" . implode(", ", $indexMeta['primary_key']) . "]\n";
echo "Predefined columns: [" . implode(", ", $indexMeta['defined_column']) . "]\n";
echo "Secondary index type: " . $indexMeta['index_type'] . "\n";
echo "Secondary index update mode: " . $indexMeta['index_update_mode'] . "\n";
}
} catch (Exception $e) {
echo 'Describe table failed.';
}