StartLocalTransaction

You can call the StartLocalTransaction operation to create a local transaction (that is, a partition-level transaction) and obtain the transaction ID.

Method
    /**
     * Create a transaction and obtain the transaction ID.
     * @api
     * @param [] $request
     *            The request parameters, including the table name and partition key.
     * @return [] The response.
     * @throws OTSClientException The exception that is thrown when a parameter check error occurs or the Table Store server returns a verification error.
     * @throws OTSServerException The exception that is thrown when the Table Store server returns an error.
     * @example "src/examples/StartLocalTransaction.php" 50
     */
    public function startLocalTransaction(array $request)
Example
$response = $this->otsClient->startLocalTransaction (array (
    'table_name' => 'TransactionTable',
    'key' => array(  // Primary keys: [PK0:INTEGER,PK1:STRING]
        array('PK0', 0)
    )
));

After obtaining the transaction ID, you must pass it when calling the PutRow, UpdateRow, and BatchWriteRow operations.

$updateRequest = array(
    'table_name' => 'TransactionTable',
    'condition' => RowExistenceExpectationConst::CONST_IGNORE,
    'primary_key' => array (
        array('PK0', 0),
        array('PK1', '1')
    ),
    'update_of_attribute_columns'=> array(
        'PUT' => array (
            array('attr0', 'new value')
        )
    ),
    'transaction_id' => $response['transaction_id']
);
$this->otsClient->updateRow($updateRequest);

CommitTransaction

You can call the CommitTransaction operation to submit a transaction.

Method
    /**
     * Submit a transaction.
     * @api
     *
     * @param [] $request
     *            The request parameter, which is the table name.
     * @return [] The response.
     * @throws OTSClientException The exception that is thrown when a parameter check error occurs or the Table Store server returns a verification error.
     * @throws OTSServerException The exception that is thrown when the Table Store server returns an error.
     * @example "src/examples/CommitTransaction.php" 50
     */
    public function commitTransaction(array $request)
Example
$this->otsClient->commitTransaction(array(
    'transaction_id' => $response['transaction_id']
));

AbortTransaction

You can call the AbortTransaction operation to abort a transaction. All requests that contain the ID of this transaction are discarded.

Method
    /**
     * Abort a transaction.
     * @api
     *
     * @param [] $request
     *          The request parameter, which is the transaction ID.
     * @return [] The response.
     * @throws OTSClientException The exception that is thrown when a parameter check error occurs or the Table Store server returns a verification error.
     * @throws OTSServerException The exception that is thrown when the Table Store server returns an error.
     * @example "src/examples/AbortTransaction.php" 20
     */
    public function abortTransaction(array $request)
Example
$this->otsClient->abortTransaction(array(
    'transaction_id' => $response['transaction_id']
));