All Products
Search
Document Center

Tablestore:Write a single row of data

更新时间:Mar 11, 2026

Use the putRow method in the PHP SDK to write a single row of data to a Tablestore table.

Before you begin

Initialize the Tablestore client

Method description

public function putRow(array $request)

Parameter description for $request

Name

Type

Description

table_name (required)

string

The name of the table.

primary_key (required)

array

The primary key information, including primary key column names and values.

  • Primary key column types include STRING, INTEGER, and BINARY.

  • The number and types of primary keys in the row must match those defined for the table.

  • If a primary key column is an auto-increment column, set its value to a placeholder. For more information, see Auto-increment primary key column.

attribute_columns (optional)

array

The attribute column information, including column names, values, and version numbers.

  • Attribute column types include STRING, INTEGER, BINARY, DOUBLE, and BOOLEAN.

  • The version number is a timestamp. By default, the system generates it automatically. To specify a version number manually, see Data versions and lifecycle.

condition (optional)

array

The write condition. For more information, see Conditional update.

return_content (optional)

array

The data to return.

  • return_type (required)array: The return type.

    • ReturnTypeConst::CONST_NONE (default): Returns no data.

    • ReturnTypeConst::CONST_PK: Returns the primary key columns. Use this to retrieve auto-increment primary key values.

    • ReturnTypeConst::CONST_AFTER_MODIFY: Returns the updated column values. Use this for atomic counters.

transaction_id (optional)

string

The local transaction ID. This uniquely identifies a local transaction. For more information, see Local transaction.

Sample code

Write one row of data to the test_table table with a primary key value of row1.

$request = array (
    'table_name' => 'test_table',
    // Build the primary key
    'primary_key' => array (
        array('id', 'row1')
    )
);

try{
    // Call putRow to write the row
    $response = $client->putRow($request);
    echo "* Read CU Cost: " . $response['consumed']['capacity_unit']['read'] . "\n";
    echo "* Write CU Cost: " . $response['consumed']['capacity_unit']['write'] . "\n";
} catch (Exception $e) {
    echo "Put Row failed.";
}
  • Add an attribute column.

    $request['attribute_columns'] = array(
        array('col1', 'val1')
    );
  • Specify a version number. Assign a separate version number to each attribute column.

    $request['attribute_columns'] = array(
        array('col1', 'val1', null, intval(microtime(true) * 1000))
    );

References

Batch update data