App in PHP

This page contains a detailed description of the code of a test app that is available as part of the YDB PHP SDK.

Note

The article is being updated.

Initializing a database connection

To interact with YDB, create an instance of the driver, client, and session:

  • The YDB driver lets the app and YDB interact at the transport layer. The driver must exist throughout the YDB access lifecycle and be initialized before creating a client or session.
  • The YDB client runs on top of the YDB driver and enables the handling of entities and transactions.
  • The YDB session contains information about executed transactions and prepared queries, and is part of the YDB client context.

App code snippet for driver initialization:

  1. <?php
  2. use YandexCloud\Ydb\Ydb;
  3. $config = [
  4. // ...
  5. ];
  6. $ydb = new Ydb($config);

PHP - 图1

App code snippet for creating a session:

  1. // obtaining the Table service
  2. $table = $ydb->table();
  3. // obtaining a session
  4. $session = $table->session();

PHP - 图2