Update attribute column values, add attribute columns, delete a specific version of an attribute column, or delete an entire attribute column in a Tablestore table by using the PHP SDK.
Before you begin
Method
public function updateRow(array $request)
Examples
The following example updates the row with the primary key value row1 in the test_table table. The attribute column col1 is set to changed_val1.
$request = array(
'table_name' => 'test_table',
// Build the primary key
'primary_key' => array(
array('id', 'row1')
),
// Specify the update condition when updating a row.
// RowExistenceExpectationConst::CONST_IGNORE means skip row existence checking.
'condition' => RowExistenceExpectationConst::CONST_IGNORE
);
// Attribute columns to update
$request['update_of_attribute_columns'] = array(
'PUT' => array(
array('col1', 'changed_val1')
)
);
try {
// Call the updateRow method to update the row
$response = $client->updateRow($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 "Update Row failed.";
}
Use the following code snippets to perform other row update operations.
-
Add an attribute column.
$request['update_of_attribute_columns'] = array( 'PUT' => array( array('col2', 'val2') ) ); -
Set the version number for an attribute column.
$request['update_of_attribute_columns'] = array( 'PUT' => array( array('col2', 'val2', null, intval(microtime(true) * 1000)) ) ); -
Delete a specific version of an attribute column.
$request['update_of_attribute_columns'] = array( 'DELETE' => array( array('col2', 1754285998447) ) ); -
Delete all data in an attribute column.
$request['update_of_attribute_columns'] = array( 'DELETE_ALL' => array('col2') );