全部產品
Search
文件中心

Tablestore:查詢表資訊

更新時間:Jun 26, 2025

本文介紹如何通過PHP SDK查詢資料表的詳細資料。

前提條件

初始化Tablestore Client

方法說明

public function describeTable(array $request)

$request參數說明

table_name(必選)string:資料表名稱。

範例程式碼

以下範例程式碼用於查詢test_table表的詳細資料。

try{
    $response = $client->describeTable(array (
        'table_name' => 'test_table',
    ));

    // 資料表結構資訊
    echo "* 資料表名稱: " . $response['table_meta']['table_name'] . "\n";
    echo "* 主鍵資訊 \n";
    foreach ($response['table_meta']['primary_key_schema'] as $primaryKey) {
        echo "{$primaryKey[0]}: {$primaryKey[1]} \n";
    }
    echo "* 預定義列資訊 \n";
    foreach ($response['table_meta']['defined_column'] as $definedColumn) {
        echo "{$definedColumn[0]}: {$definedColumn[1]} \n";
    }

    // 資料表配置資訊
    echo "* 資料表配置資訊 \n";
    echo "資料生命週期: " . $response['table_options']['time_to_live'] . "\n";
    echo "最大版本數: " . $response['table_options']['max_versions'] . "\n";
    echo "有效版本偏差: " . $response['table_options']['deviation_cell_version_in_sec'] . "\n";
    echo "是否允許更新: " . ($response['table_options']['allow_update'] ? 'true' : "false") . "\n";

    // 資料表Stream資訊
    echo "* 是否開啟Steam: " . ($response['stream_details']['enable_stream'] ? 'true' : "false") . "\n";
    if($response['stream_details']['enable_stream']){
        echo "Stream到期時間: " . $response['stream_details']['expiration_time'] . "\n";
    }

    // 資料表預留讀寫輸送量
    echo "* 預留讀寫輸送量 \n";
    echo "預留讀輸送量: " . $response['capacity_unit_details']['capacity_unit']['read'] . "\n";
    echo "預留寫輸送量: " . $response['capacity_unit_details']['capacity_unit']['write'] . "\n";

    // 二級索引資訊
    foreach ($response['index_metas'] as $indexMeta) {
        echo "* 二級索引名稱: " . $indexMeta['name'] . "\n";
        echo "主鍵列表: [" . implode(", ", $indexMeta['primary_key']) . "]\n";
        echo "預定義列列表: [" . implode(", ", $indexMeta['defined_column']) . "]\n";
        echo "二級索引類型: " . $indexMeta['index_type'] . "\n";
        echo "二級索引更新模式: " . $indexMeta['index_update_mode'] . "\n";
    }
} catch (Exception $e) {
    echo 'Describe table failed.';
}