After you install Tablestore SDK for PHP, you can call the operations of the SDK when you write code. This topic describes how to install Tablestore SDK for PHP.
Prerequisites
64-bit PHP 5.5 or later is installed.
You can run the
php -v
command to view the current PHP version.Tablestore uses 64-bit integers. However, in 32-bit PHP, only the STRING type can be used to represent 64-bit INTEGER values. 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, you must upgrade PHP to PHP 7 or modify the environment yourself. We recommend that you use PHP 7 to obtain the optimal performance.
The OpenSSL extension is installed.
You must install the OpenSSL PHP extension if you use HTTPS.
PHP development tools, such as Eclipse for PHP, are installed.
(Recommended) The cURL extension is installed.
You can run the
php -m
command to check whether the cURL extension is installed.NoteIn 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.
Installation methods
You can install Tablestore SDK for PHP by using Composer or downloading the source code.
Use Composer
To install Tablestore SDK for PHP by using Composer, perform the following steps:
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" }
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';
NoteIf your project already has autoload.php imported, 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
Download the source code
You can download the source code package by using the following methods:
Download the source code package of the required version from GitHub. For more information, visit GitHub.
Obtain the source code from the SDK package. For more information about the download path, see SDK 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. Find the sample programs in the examples directory.
Access the GitHub project for Tablestore SDK for PHP. For more information, visit aliyun-tablestore-php-sdk.
To run a sample program, perform the following steps:
Decompress the SDK package that you downloaded.
Modify the ExampleConfig.php file in the examples directory.
EXAMPLE_END_POINT: the endpoint of the region in which the Tablestore instance that you want to access resides. Example: https://sun.cn-hangzhou.ots.aliyuncs.com. EXAMPLE_ACCESS_KEY_ID: the AccessKey ID that you obtained from Alibaba Cloud. EXAMPLE_ACCESS_KEY_ID: the AccessKey secret that you obtained from Alibaba Cloud. EXAMPLE_INSTANCE_NAME: the instance that you use to run the sample program. The sample program is operated in this instance.
Separately run a sample file in the examples directory.
The following table describes common sample programs. Use sample programs based on your business requirements.
Module
Sample file
Content
Initialization operations
Shows you how to configure the default client.
Shows you how to configure a custom client.
Shows you how to disable the logs of the client.
Shows you how to configure custom logs for the client.
Operations on data tables
Shows you how to use CreateTable.
Shows you how to use DeleteTable.
Shows you how to use DescribeTable.
Shows you how to use ListTable.
Shows you how to use UpdateTable.
Shows you how to use ComputeSplitPointsBySize.
Shows you how to use an auto-increment primary key column.
Basic data operations
Shows you how to use PutRow.
Shows you how to use PutRow with conditional update.
Shows you how to use PUT in UpdateRow.
Shows you how to use DELETE_ALL in UpdateRow.
Shows you how to use DELETE in UpdateRow.
Shows you how to use UpdateRow with conditional update.
Shows you how to use GetRow.
Shows you how to configure column_to_get in GetRow.
Shows you how to use GetRow with conditional filtering.
Shows you how to use GetRow with complex conditional filtering.
Shows you how to use DeleteRow.
Shows you how to use DeleteRow based on specific conditions.
Shows you how to use BatchGetRow to read multiple rows from a table.
Shows you how to use BatchGetRow to read multiple rows from multiple tables.
Shows you how to use BatchGetRow to read specific columns of multiple rows from a table.
Shows you how to use BatchGetRow to process returned results.
Shows you how to use BatchGetRow with conditional filtering.
Shows you how to perform multiple PUT operations in BatchWriteRow.
Shows you how to perform multiple UPDATE operations in BatchWriteRow.
Shows you how to perform multiple DELETE operations in BatchWriteRow.
Shows you how to perform the UPDATE, PUT, and DELETE operations in BatchWriteRow.
Shows you how to use BatchWriteRow with conditional update.
Shows you how to use GetRange.
Shows you how to use GetRange to obtain the specified columns.
Shows you how to use GetRange to obtain the specified number of rows.
Shows you how to use GetRange with conditional filtering.
Operations on search indexes
Shows you how to use CreateSearchIndex.
Shows you how to use DeleteSearchIndex.
Shows you how to use DescribeSearchIndex.
Shows you how to use ListSearchIndex.
Shows you how to use UpdateSearchIndex.
Shows you how to use BoolQuery of search indexes.
Shows you how to use ExistsQuery of search indexes.
Shows you how to use GeoBoundingBoxQuery of search indexes.
Shows you how to use SearchGeoDistanceQuery of search indexes.
Shows you how to use GeoPolygonQuery of search indexes.
Shows you how to use MatchAllQuery of search indexes.
Shows you how to use MatchPhraseQuery of search indexes.
Shows you how to use MatchQuery of search indexes.
Shows you how to use NestedQuery of search indexes.
Shows you how to use PrefixQuery of search indexes.
Shows you how to use RangeQuery of search indexes.
Shows you how to use TermQuery of search indexes.
Shows you how to use TermsQuery of search indexes.
Shows you how to use WildcardQuery of search indexes.
Shows you how to use aggregation of search indexes.
SQL query operations
Shows you how to use the SQL query feature to query data.
Shows you how to use the SQL query feature to query time series data.