This topic describes how to install and use Tablestore SDK for PHP.

Prerequisites

  • 64-bit PHP 5.5 or later is available.

    You can run the php -v command to check the current PHP version. Tablestore uses 64-bit integers. However, only the STRING type can be used to represent the 64-bit INTEGER type in 32-bit PHP. Therefore, Tablestore does not support 32-bit PHP. In Windows, PHP versions earlier than PHP 7 are not actually 64-bit. When you run PHP in Windows, upgrade PHP to PHP 7 or modify the environment by yourself. We recommend that you use PHP 7 to obtain the optimal performance.

  • cURL extension: optional. You can run the php -m command to check whether the cURL extension is installed.
    Note
    • In Ubuntu, you can run the sudo apt-get install php-curl command to install the cURL extension of PHP by using apt-get.
    • In CentOS, you can run the sudo yum install php-curl command to install the cURL extension of PHP by using YUM.
  • OpenSSL extension: optional. You must install the OpenSSL PHP extension if you use HTTPS.

Installation methods

  • Composer
    To install Tablestore SDK for PHP by using Composer, perform the following operations:
    1. Run the composer require aliyun/aliyun-tablestore-sdk-php command in the root directory of the project or declare the dependency on Tablestore SDK for PHP in the composer.json file.
      "require": { "aliyun/aliyun-tablestore-sdk-php": "~5.0" }
    2. Run the composer install command to install the dependency. After the dependency is installed, check whether your directory structure complies with the following structure:
       .
       ├── app.php
       ├── composer.json
       ├── composer.lock
       └── vendor
      								

      In the preceding directory structure, app.php indicates your application. The vendor directory contains the dependent library. You must import the dependency into app.php.

      require_once __DIR__ . '/vendor/autoload.php';
      								
      Note
      • If your project has imported autoload.php, you do not need to import autoload.php again after you add the SDK dependency.
      • If a network error occurs when you use Composer, you can enter the following command on the command line to use Packagist that is available to China: composer config -g repo.packagist composer https://developer.aliyun.com/composer. For more information about Packagist, visit Images.
  • Source code package
    You can download the source code package by using one of the following methods:
    • Select the required version and download the ZIP package at GitHub.
    • Click here to download the source code package.

Sample programs

Tablestore SDK for PHP provides a variety of sample programs for your reference or use. You can obtain the sample programs by using one of the following methods:

  • Download and decompress Tablestore SDK for PHP. Locate the sample programs in the examples directory.

  • Access the GitHub project for Tablestore SDK for PHP at aliyun-tablestore-php-sdk.

To run a sample program, perform the following operations:

  • Decompress the downloaded SDK package.

  • Modify the ExampleConfig.php file in the examples directory.

    EXAMPLE_END_POINT: the AccessKey ID that you obtained from Alibaba Cloud.
    EXAMPLE_ACCESS_KEY_ID: the AccessKey secret that you obtained from Alibaba Cloud.
    EXAMPLE_ACCESS_KEY_SECRET: the domain name that you use to access the region where your Tablestore is located. Example: https://sun.cn-hangzhou.ots.aliyuncs.com.
    EXAMPLE_INSTANCE_NAME: the instance that you use to run the sample program. The sample program is operated in this instance.
  • Run a sample file in the examples directory separately.

The following table lists the sample files.

File Description
NewClient.php Shows you how to configure the default client.
NewClient2.php Shows you how to customize the client.
NewClientLogClosed.php Shows you how to disable the display of logs of the client.
NewClientLogDefined.php Shows you how to customize the display of logs of the client.
CreateTable.php Shows you how to use CreateTable.
DeleteTable.php Shows you how to use DeleteTable.
DescribeTable.php Shows you how to use DescribeTable.
ListTable.php Shows you how to use ListTable.
UpdateTable.php Shows you how to use UpdateTable.
ComputeSplitPointsBySize.php Shows you how to use ComputeSplitPointsBySize.
PutRow.php Shows you how to use PutRow.
PutRowWithColumnFilter.php Shows you how to use PutRow with conditional update.
UpdateRow1.php Shows you how to use PUT in UpdateRow.
UpdateRow2.php Shows you how to use DELETE_ALL in UpdateRow.
UpdateRow3.php Shows you how to use DELETE in UpdateRow.
UpdateRowWithColumnFilter.php Shows you how to use UpdateRow with conditional update.
GetRow.php Shows you how to use GetRow.
GetRow2.php Shows you how to set column_to_get in GetRow.
GetRowWithSingleColumnFilter.php Shows you how to use GetRow with conditional filtering.
GetRowWithMultipleColumnFilter.php Shows you how to use GetRow with complex conditional filtering.
DeleteRow.php Shows you how to use DeleteRow.
DeleteRowWithColumnFilter.php Shows you how to use DeleteRow with conditional filtering.
PKAutoIncrment.php Shows you how to use auto-increment primary key columns in detail.
BatchGetRow1.php Shows you how to use BatchGetRow to read multiple rows from a table.
BatchGetRow2.php Shows you how to use BatchGetRow to read multiple rows from multiple tables.
BatchGetRow3.php Shows you how to use BatchGetRow to read specified columns for multiple rows from a table.
BatchGetRow4.php Shows you how to use BatchGetRow to process returned results.
BatchGetRowWithColumnFilter.php Shows you how to use BatchGetRow with conditional filtering.
BatchWriteRow1.php Shows you how to perform multiple PUT operations in BatchWriteRow.
BatchWriteRow2.php Shows you how to perform multiple UPDATE operations in BatchWriteRow.
BatchWriteRow3.php Shows you how to perform multiple DELETE operations in BatchWriteRow.
BatchWriteRow4.php Shows you how to simultaneously perform the UPDATE, PUT, and DELETE operations in BatchWriteRow.
BatchWriteRowWithColumnFilter.php Shows you how to use BatchWriteRow with conditional update.
GetRange1.php Shows you how to use GetRange.
GetRange2.php Shows you how to use GetRange to obtain the specified columns.
GetRange3.php Shows you how to use GetRange to obtain the specified number of rows.
GetRangeWithColumnFilter.php Shows you how to use GetRange with conditional filtering.