Download the PHP package yandex-cloud/ydb-php-sdk without Composer
On this page you can find all versions of the php package yandex-cloud/ydb-php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package ydb-php-sdk
YDB PHP SDK provides access to YDB from PHP code.
YDB is a open-source distributed fault-tolerant DBMS with high availability and scalability, strict consistency and ACID. An SQL dialect – YQL – is used for queries.
YDB is available in several modes:
- On-prem installation (is not supported by this SDK yet);
- Serverless computing mode in YC (only performed operations are paid);
- Dedicated instance mode in YC (dedicated computing resources are paid).
Documentation
Installation
The recommended method of installing is Composer.
Run the following:
Connection
First, create a database using Yandex Cloud Console.
YDB supports the following authentication methods:
- Access token
- OAuth token
- JWT + private key
- JWT + JSON file
- Metadata URL
- Anonymous
Access token
Use your access token:
or:
OAuth token
You should obtain a new OAuth token.
Use your OAuth token:
or
JWT + private key
Create a service account with the editor
role, then create a private key. Also you need a key ID and a service account ID.
Connect to your database:
or
JWT + JSON file
Create a service account with the editor
role.
Create a service account JSON file, save it in your project as sa_name.json
.
Connect to your database:
or:
Metadata URL
When you deploy a project to VM or function at Yandex.Cloud, you are able to connect to the database using Metadata URL. Before you start, you should link your service account to an existing or new VM or function.
or
Anonymous
or:
Determined by environment variables
The following algorithm that is the same for YDB-PHP-SDK applies:
- If the value of the
YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS
environment variable is set, the System Account Key authentication mode is used and the key is taken from the file whose name is specified in this variable. - Otherwise, if the value of the
YDB_ANONYMOUS_CREDENTIALS
environment variable is set to 1, the anonymous authentication mode is used. - Otherwise, if the value of the
YDB_METADATA_CREDENTIALS
environment variable is set to 1, the Metadata authentication mode is used. - Otherwise, if the value of the
YDB_ACCESS_TOKEN_CREDENTIALS
environment variable is set, the Access token authentication mode is used, where the this variable value is passed. - Otherwise, the Metadata authentication mode is used.
Static credentials
Reading from text file
Usage
You should initialize a session from the Table service to start querying with retry.
As soon as your script is finished, the session will be destroyed.
Customizing queries
Normally, a regular query through the query()
method is sufficient, but in exceptional cases, you may need to fine-tune the query settings. You could do it using the query builder:
Methods of the query builder:
keepInCache(bool $value)
- keep in cache (default:true
)collectStats(int $value)
- collect stats (default: 1)parameters(array $parameters)
- parametersoperationParams(\Ydb\Operations\OperationParams $operation_params)
- operation paramsbeginTx(string $mode)
- begin a transaction with the given mode:- stale
- online
- online_inconsistent
- serializable
- snapshot
txControl(\Ydb\Table\TransactionControl $tx_control)
- transaction control with custom settings
You can chain these methods for convenience.
Logging
For logging purposes, you need use class, which implements \Psr\Log\LoggerInterface
.
YDB-PHP-SDK has build-in loggers in YdbPlatform\Ydb\Logger
namespace:
NullLogger
- defaultSimpleStdLogger($level)
- logger, which push logs in STDERR.
Example of using:
gRPC
gRPC client's options
You can customize the gRPC client's behavior by setting options in config array
Example of using:
All versions of ydb-php-sdk with dependencies
ext-bcmath Version *
ext-curl Version *
ext-grpc Version *
ext-json Version *
google/protobuf Version ~3.15.8
grpc/grpc Version ^1.35
phpseclib/phpseclib Version ^2.0|^3.0
psr/log Version ^1|^2|^3