{"id":13792658,"url":"https://github.com/tarantool-php/client","last_synced_at":"2025-04-06T02:09:29.735Z","repository":{"id":31399575,"uuid":"34962787","full_name":"tarantool-php/client","owner":"tarantool-php","description":"PHP client for Tarantool.","archived":false,"fork":false,"pushed_at":"2024-06-20T23:13:52.000Z","size":709,"stargazers_count":65,"open_issues_count":1,"forks_count":22,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-09-21T13:23:46.573Z","etag":null,"topics":["lua","nosql","php","sql","tarantool","tarantool-client","tarantool-connector"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tarantool-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["rybakit"]}},"created_at":"2015-05-02T20:46:19.000Z","updated_at":"2024-08-23T15:17:41.000Z","dependencies_parsed_at":"2022-09-10T10:39:47.912Z","dependency_job_id":"86d5b36a-24c0-42ef-aac1-30abf0012596","html_url":"https://github.com/tarantool-php/client","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool-php%2Fclient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool-php%2Fclient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool-php%2Fclient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool-php%2Fclient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tarantool-php","download_url":"https://codeload.github.com/tarantool-php/client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423515,"owners_count":20936626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lua","nosql","php","sql","tarantool","tarantool-client","tarantool-connector"],"created_at":"2024-08-03T22:01:14.791Z","updated_at":"2025-04-06T02:09:29.702Z","avatar_url":"https://github.com/tarantool-php.png","language":"PHP","readme":"# PHP client for Tarantool\n\n[![Quality Assurance](https://github.com/tarantool-php/client/workflows/QA/badge.svg)](https://github.com/tarantool-php/client/actions?query=workflow%3AQA)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/tarantool-php/client/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/tarantool-php/client/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/tarantool-php/client/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/tarantool-php/client/?branch=master)\n[![Telegram](https://img.shields.io/badge/Telegram-join%20chat-blue.svg)](https://t.me/tarantool_php)\n\nA pure PHP client for [Tarantool](https://www.tarantool.io/en/developers/) 1.7.1 or above.\n\n\n## Features\n\n * Written in pure PHP, no extensions are required\n * Supports Unix domain sockets\n * Supports SQL protocol\n * Supports user-defined types (decimals and UUIDs are included)\n * Highly customizable\n * [Thoroughly tested](https://github.com/tarantool-php/client/actions?query=workflow%3AQA)\n * Being used in a number of projects, including [Queue](https://github.com/tarantool-php/queue), \n   [Mapper](https://github.com/tarantool-php/mapper), [Web Admin](https://github.com/basis-company/tarantool-admin) \n   and [others](https://github.com/tarantool-php).\n\n\n## Table of contents\n\n * [Installation](#installation)\n * [Creating a client](#creating-a-client)\n * [Handlers](#handlers)\n * [Middleware](#middleware)\n * [Data manipulation](#data-manipulation)\n   * [Binary protocol](#binary-protocol)\n   * [SQL protocol](#sql-protocol)\n   * [User-defined types](#user-defined-types) \n * [Tests](#tests)\n * [Benchmarks](#benchmarks)\n * [License](#license)\n\n\n## Installation\n\nThe recommended way to install the library is through [Composer](http://getcomposer.org):\n\n```bash\ncomposer require tarantool/client\n```\n\nIn order to use the [Decimal](https://www.tarantool.io/en/doc/latest/dev_guide/internals/msgpack_extensions/#the-decimal-type) \ntype that was added in Tarantool 2.3, you additionally need to install the [decimal](http://php-decimal.io/#installation) \nextension. Also, to improve performance when working with the [UUID](https://www.tarantool.io/en/doc/latest/dev_guide/internals/msgpack_extensions/#the-uuid-type) \ntype, which is available since Tarantool 2.4, it is recommended to additionally install the [uuid](https://pecl.php.net/package/uuid) extension. \n\n\n## Creating a client\n\nThe easiest way to create a client is by using the default configuration:\n\n```php\nuse Tarantool\\Client\\Client;\n\n$client = Client::fromDefaults();\n```\n\nThe client will be configured to connect to `127.0.0.1` on port `3301` with the default stream connection options.\nAlso, the best available msgpack package will be chosen automatically. A custom configuration can be accomplished\nby one of several methods listed.\n\n#### DSN string\n\nThe client supports the following Data Source Name formats:\n\n```\ntcp://[[username[:password]@]host[:port][/?option1=value1\u0026optionN=valueN]\nunix://[[username[:password]@]path[/?option1=value1\u0026optionN=valueN]\n```\n\nSome examples:\n\n```php\nuse Tarantool\\Client\\Client;\n\n$client = Client::fromDsn('tcp://127.0.0.1');\n$client = Client::fromDsn('tcp://[fe80::1]:3301');\n$client = Client::fromDsn('tcp://user:pass@example.com:3301');\n$client = Client::fromDsn('tcp://user@example.com/?connect_timeout=5.0\u0026max_retries=3');\n$client = Client::fromDsn('unix:///var/run/tarantool/my_instance.sock');\n$client = Client::fromDsn('unix://user:pass@/var/run/tarantool/my_instance.sock?max_retries=3');\n```\n\nIf the username, password, path or options include special characters such as `@`, `:`, `/` or `%`,\nthey must be encoded according to [RFC 3986](https://tools.ietf.org/html/rfc3986#section-2.1)\n(for example, with the [rawurlencode()](https://www.php.net/manual/en/function.rawurlencode.php) function).\n\n\n#### Array of options\n\nIt is also possible to create the client from an array of configuration options:\n\n```php\nuse Tarantool\\Client\\Client;\n\n$client = Client::fromOptions([\n    'uri' =\u003e 'tcp://127.0.0.1:3301',\n    'username' =\u003e '\u003cusername\u003e',\n    'password' =\u003e '\u003cpassword\u003e',\n    ...\n);\n```\n\nThe following options are available:\n\nName | Type | Default | Description\n--- | :---: | :---: | ---\n*uri* | string | 'tcp://127.0.0.1:3301' | The connection uri that is used to create a `StreamConnection` object.\n*connect_timeout* | float | 5.0 | The number of seconds that the client waits for a connect to a Tarantool server before throwing a `ConnectionFailed` exception.\n*socket_timeout* | float | 5.0 | The number of seconds that the client waits for a respond from a Tarantool server before throwing a `CommunicationFailed` exception.\n*tcp_nodelay* | boolean | true | Whether the Nagle algorithm is disabled on a TCP connection.\n*persistent* | boolean | false | Whether to use a persistent connection.\n*username* | string | | The username for the user being authenticated.\n*password* | string | '' | The password for the user being authenticated. If the username is not set, this option will be ignored.\n*max_retries* | integer | 0 | The number of times the client retries unsuccessful request. If set to 0, the client does not try to resend the request after the initial unsuccessful attempt.\n\n\n#### Custom build\n\nFor more deep customisation, you can build a client from the ground up:\n\n```php\nuse MessagePack\\BufferUnpacker;\nuse MessagePack\\Packer;\nuse Tarantool\\Client\\Client;\nuse Tarantool\\Client\\Connection\\StreamConnection;\nuse Tarantool\\Client\\Handler\\DefaultHandler;\nuse Tarantool\\Client\\Handler\\MiddlewareHandler;\nuse Tarantool\\Client\\Middleware\\AuthenticationMiddleware;\nuse Tarantool\\Client\\Middleware\\RetryMiddleware;\nuse Tarantool\\Client\\Packer\\PurePacker;\n\n$connection = StreamConnection::createTcp('tcp://127.0.0.1:3301', [\n    'socket_timeout' =\u003e 5.0,\n    'connect_timeout' =\u003e 5.0,\n    // ...\n]);\n\n$pureMsgpackPacker = new Packer();\n$pureMsgpackUnpacker = new BufferUnpacker();\n$packer = new PurePacker($pureMsgpackPacker, $pureMsgpackUnpacker);\n\n$handler = new DefaultHandler($connection, $packer);\n$handler = MiddlewareHandler::append($handler, [\n    RetryMiddleware::exponential(3),\n    new AuthenticationMiddleware('\u003cusername\u003e', '\u003cpassword\u003e'),\n    // ...\n]);\n\n$client = new Client($handler);\n```\n\n\n## Handlers\n\nA handler is a function which transforms a request into a response. Once you have created a handler object,\nyou can make requests to Tarantool, for example:\n\n```php\nuse Tarantool\\Client\\Keys;\nuse Tarantool\\Client\\Request\\CallRequest;\n\n...\n\n$request = new CallRequest('box.stat');\n$response = $handler-\u003ehandle($request);\n$data = $response-\u003egetBodyField(Keys::DATA);\n```\n\nThe library ships with two handlers:\n\n * `DefaultHandler` is used for handling low-level communication with a Tarantool server\n * `MiddlewareHandler` is used as an extension point for an underlying handler via [middleware](#middleware)\n\n\n## Middleware\n\nMiddleware is the suggested way to extend the client with custom functionality. There are several middleware classes\nimplemented to address the common use cases, like authentification, logging and [more](src/Middleware).\nThe usage is straightforward:\n\n```php\nuse Tarantool\\Client\\Client;\nuse Tarantool\\Client\\Middleware\\AuthenticationMiddleware;\n\n$client = Client::fromDefaults()-\u003ewithMiddleware(\n    new AuthenticationMiddleware('\u003cusername\u003e', '\u003cpassword\u003e')\n);\n```\n\nYou may also assign multiple middleware to the client (they will be executed in [FIFO](https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)) order):\n\n```php\nuse Tarantool\\Client\\Client;\nuse Tarantool\\Client\\Middleware\\FirewallMiddleware;\nuse Tarantool\\Client\\Middleware\\LoggingMiddleware;\nuse Tarantool\\Client\\Middleware\\RetryMiddleware;\n\n...\n\n$client = Client::fromDefaults()-\u003ewithMiddleware(\n    FirewallMiddleware::allowReadOnly(),\n    RetryMiddleware::linear(),\n    new LoggingMiddleware($logger)\n);\n```\n\nPlease be aware that the order in which you add the middleware does matter. The same middleware,\nplaced in different order, can give very different or sometimes unexpected behavior.\nTo illustrate, consider the following configurations:\n\n```php\n$client1 = Client::fromDefaults()-\u003ewithMiddleware(\n    RetryMiddleware::linear(),\n    new AuthenticationMiddleware('\u003cusername\u003e', '\u003cpassword\u003e') \n);\n\n$client2 = Client::fromDefaults()-\u003ewithMiddleware(\n    new AuthenticationMiddleware('\u003cusername\u003e', '\u003cpassword\u003e'), \n    RetryMiddleware::linear()\n);\n\n$client3 = Client::fromOptions([\n    'username' =\u003e '\u003cusername\u003e',\n    'password' =\u003e '\u003cpassword\u003e',\n])-\u003ewithMiddleware(RetryMiddleware::linear());\n```\n\nIn this example, `$client1` will retry an unsuccessful operation and in case of connection\nproblems may initiate reconnection with follow-up re-authentication. However, `$client2`\nand `$client3` will perform reconnection *without* doing any re-authentication.\n\n\u003e *You may wonder why `$client3` behaves like `$client2` in this case. This is because\n\u003e specifying some options (via array or DSN string) may implicitly register middleware.\n\u003e Thus, the `username/password` options will be turned into `AuthenticationMiddleware`\n\u003e under the hood, making the two configurations identical.*\n\nTo make sure your middleware runs first, use the `withPrependedMiddleware()` method:\n\n```php\n$client = $client-\u003ewithPrependedMiddleware($myMiddleware);\n```\n\n\n## Data manipulation\n\n### Binary protocol\n\nThe following are examples of binary protocol requests. For more detailed information and examples please see\nthe [official documentation](https://www.tarantool.io/en/doc/latest/book/box/data_model/#operations).\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eSelect\u003c/strong\u003e\u003c/summary\u003e\u003cbr /\u003e\n\n*Fixtures*\n\n```lua\nlocal space = box.schema.space.create('example')\nspace:create_index('primary', {type = 'tree', parts = {1, 'unsigned'}})\nspace:create_index('secondary', {type = 'tree', unique = false, parts = {2, 'str'}})\nspace:insert({1, 'foo'})\nspace:insert({2, 'bar'})\nspace:insert({3, 'bar'})\nspace:insert({4, 'bar'})\nspace:insert({5, 'baz'})\n```\n\n*Code*\n\n```php\n$space = $client-\u003egetSpace('example');\n$result1 = $space-\u003eselect(Criteria::key([1]));\n$result2 = $space-\u003eselect(Criteria::index('secondary')\n    -\u003eandKey(['bar'])\n    -\u003eandLimit(2)\n    -\u003eandOffset(1)\n);\n\nprintf(\"Result 1: %s\\n\", json_encode($result1));\nprintf(\"Result 2: %s\\n\", json_encode($result2));\n```\n\n*Output*\n\n```\nResult 1: [[1,\"foo\"]]\nResult 2: [[3,\"bar\"],[4,\"bar\"]]\n```\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eInsert\u003c/strong\u003e\u003c/summary\u003e\u003cbr /\u003e\n\n*Fixtures*\n\n```lua\nlocal space = box.schema.space.create('example')\nspace:create_index('primary', {type = 'tree', parts = {1, 'unsigned'}})\n```\n\n*Code*\n\n```php\n$space = $client-\u003egetSpace('example');\n$result = $space-\u003einsert([1, 'foo', 'bar']);\n\nprintf(\"Result: %s\\n\", json_encode($result));\n```\n\n*Output*\n\n```\nResult: [[1,\"foo\",\"bar\"]]\n```\n\n*Space data*\n\n```lua\ntarantool\u003e box.space.example:select()\n---\n- - [1, 'foo', 'bar']\n...\n```\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eUpdate\u003c/strong\u003e\u003c/summary\u003e\u003cbr /\u003e\n\n*Fixtures*\n\n```lua\nlocal space = box.schema.space.create('example')\nspace:create_index('primary', {type = 'tree', parts = {1, 'unsigned'}})\nspace:format({\n    {name = 'id', type = 'unsigned'}, \n    {name = 'num', type = 'unsigned'}, \n    {name = 'name', type = 'string'}\n})\n\nspace:insert({1, 10, 'foo'})\nspace:insert({2, 20, 'bar'})\nspace:insert({3, 30, 'baz'})\n```\n\n*Code*\n\n```php\n$space = $client-\u003egetSpace('example');\n$result = $space-\u003eupdate([2], Operations::add(1, 5)-\u003eandSet(2, 'BAR'));\n\n// Since Tarantool 2.3 you can refer to tuple fields by name:\n// $result = $space-\u003eupdate([2], Operations::add('num', 5)-\u003eandSet('name', 'BAR'));\n\nprintf(\"Result: %s\\n\", json_encode($result));\n```\n\n*Output*\n\n```\nResult: [[2,25,\"BAR\"]]\n```\n\n*Space data*\n\n```lua\ntarantool\u003e box.space.example:select()\n---\n- - [1, 10, 'foo']\n  - [2, 25, 'BAR']\n  - [3, 30, 'baz']\n...\n```\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eUpsert\u003c/strong\u003e\u003c/summary\u003e\u003cbr /\u003e\n\n*Fixtures*\n\n```lua\nlocal space = box.schema.space.create('example')\nspace:create_index('primary', {type = 'tree', parts = {1, 'unsigned'}}) \nspace:format({\n    {name = 'id', type = 'unsigned'}, \n    {name = 'name1', type = 'string'}, \n    {name = 'name2', type = 'string'}\n})\n```\n\n*Code*\n\n```php\n$space = $client-\u003egetSpace('example');\n$space-\u003eupsert([1, 'foo', 'bar'], Operations::set(1, 'baz'));\n$space-\u003eupsert([1, 'foo', 'bar'], Operations::set(2, 'qux'));\n\n// Since Tarantool 2.3 you can refer to tuple fields by name:\n// $space-\u003eupsert([1, 'foo', 'bar'], Operations::set('name1', 'baz'));\n// $space-\u003eupsert([1, 'foo', 'bar'], Operations::set('name2'', 'qux'));\n```\n\n*Space data*\n\n```lua\ntarantool\u003e box.space.example:select()\n---\n- - [1, 'foo', 'qux']\n...\n```\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eReplace\u003c/strong\u003e\u003c/summary\u003e\u003cbr /\u003e\n\n*Fixtures*\n\n```lua\nlocal space = box.schema.space.create('example')\nspace:create_index('primary', {type = 'tree', parts = {1, 'unsigned'}})\nspace:insert({1, 'foo'})\nspace:insert({2, 'bar'})\n```\n\n*Code*\n\n```php\n$space = $client-\u003egetSpace('example');\n$result1 = $space-\u003ereplace([2, 'BAR']);\n$result2 = $space-\u003ereplace([3, 'BAZ']);\n\nprintf(\"Result 1: %s\\n\", json_encode($result1));\nprintf(\"Result 2: %s\\n\", json_encode($result2));\n```\n\n*Output*\n\n```\nResult 1: [[2,\"BAR\"]]\nResult 2: [[3,\"BAZ\"]]\n```\n\n*Space data*\n\n```lua\ntarantool\u003e box.space.example:select()\n---\n- - [1, 'foo']\n  - [2, 'BAR']\n  - [3, 'BAZ']\n...\n```\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eDelete\u003c/strong\u003e\u003c/summary\u003e\u003cbr /\u003e\n\n*Fixtures*\n\n```lua\nlocal space = box.schema.space.create('example')\nspace:create_index('primary', {type = 'tree', parts = {1, 'unsigned'}})\nspace:create_index('secondary', {type = 'tree', parts = {2, 'str'}})\nspace:insert({1, 'foo'})\nspace:insert({2, 'bar'})\nspace:insert({3, 'baz'})\nspace:insert({4, 'qux'})\n```\n\n*Code*\n\n```php\n$space = $client-\u003egetSpace('example');\n$result1 = $space-\u003edelete([2]);\n$result2 = $space-\u003edelete(['baz'], 'secondary');\n\nprintf(\"Result 1: %s\\n\", json_encode($result1));\nprintf(\"Result 2: %s\\n\", json_encode($result2));\n```\n\n*Output*\n\n```\nResult 1: [[2,\"bar\"]]\nResult 2: [[3,\"baz\"]]\n```\n\n*Space data*\n\n```lua\ntarantool\u003e box.space.example:select()\n---\n- - [1, 'foo']\n  - [4, 'qux']\n...\n```\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eCall\u003c/strong\u003e\u003c/summary\u003e\u003cbr /\u003e\n\n*Fixtures*\n\n```lua\nfunction func_42()\n    return 42\nend\n```\n\n*Code*\n\n```php\n$result1 = $client-\u003ecall('func_42');\n$result2 = $client-\u003ecall('math.min', 5, 3, 8);\n\nprintf(\"Result 1: %s\\n\", json_encode($result1));\nprintf(\"Result 2: %s\\n\", json_encode($result2));\n```\n\n*Output*\n\n```\nResult 1: [42]\nResult 2: [3]\n```\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eEvaluate\u003c/strong\u003e\u003c/summary\u003e\u003cbr /\u003e\n\n*Code*\n\n```php\n$result1 = $client-\u003eevaluate('function func_42() return 42 end');\n$result2 = $client-\u003eevaluate('return func_42()');\n$result3 = $client-\u003eevaluate('return math.min(...)', 5, 3, 8);\n\nprintf(\"Result 1: %s\\n\", json_encode($result1));\nprintf(\"Result 2: %s\\n\", json_encode($result2));\nprintf(\"Result 3: %s\\n\", json_encode($result3));\n```\n\n*Output*\n\n```\nResult 1: []\nResult 2: [42]\nResult 3: [3]\n```\n\u003c/details\u003e\n\n\n### SQL protocol\n\nThe following are examples of SQL protocol requests. For more detailed information and examples please see\nthe [official documentation](https://www.tarantool.io/en/doc/latest/reference/reference_sql/sql/). \n*Note that SQL is supported only as of Tarantool 2.0.*\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eExecute\u003c/strong\u003e\u003c/summary\u003e\u003cbr /\u003e\n\n*Code*\n\n```php\n$client-\u003eexecute('CREATE TABLE users (\"id\" INTEGER PRIMARY KEY AUTOINCREMENT, \"email\" VARCHAR(255))');\n\n$result1 = $client-\u003eexecuteUpdate('CREATE UNIQUE INDEX email ON users (\"email\")');\n\n$result2 = $client-\u003eexecuteUpdate('\n    INSERT INTO users VALUES (null, :email1), (null, :email2)\n',\n    [':email1' =\u003e 'foo@example.com'],\n    [':email2' =\u003e 'bar@example.com']\n);\n\n$result3 = $client-\u003eexecuteQuery('SELECT * FROM users WHERE \"email\" = ?', 'foo@example.com');\n$result4 = $client-\u003eexecuteQuery('SELECT * FROM users WHERE \"id\" IN (?, ?)', 1, 2);\n\nprintf(\"Result 1: %s\\n\", json_encode([$result1-\u003ecount(), $result1-\u003egetAutoincrementIds()]));\nprintf(\"Result 2: %s\\n\", json_encode([$result2-\u003ecount(), $result2-\u003egetAutoincrementIds()]));\nprintf(\"Result 3: %s\\n\", json_encode([$result3-\u003ecount(), $result3[0]]));\nprintf(\"Result 4: %s\\n\", json_encode(iterator_to_array($result4)));\n```\n\n*Output*\n\n```\nResult 1: [1,[]]\nResult 2: [2,[1,2]]\nResult 3: [1,{\"id\":1,\"email\":\"foo@example.com\"}]\nResult 4: [{\"id\":1,\"email\":\"foo@example.com\"},{\"id\":2,\"email\":\"bar@example.com\"}]\n```\n\nIf you need to execute a dynamic SQL statement whose type you don't know, you can use the generic method `execute()`. \nThis method returns a Response object with the body containing either an array of result set rows or an array\nwith information about the changed rows:\n\n```php\n$response = $client-\u003eexecute('\u003cany-type-of-sql-statement\u003e');\n$resultSet = $response-\u003etryGetBodyField(Keys::DATA);\n\nif ($resultSet === null) {\n    $sqlInfo = $response-\u003egetBodyField(Keys::SQL_INFO);\n    $affectedCount = $sqlInfo[Keys::SQL_INFO_ROW_COUNT];\n} \n``` \n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003ePrepare\u003c/strong\u003e\u003c/summary\u003e\u003cbr /\u003e\n\n*Note that the `prepare` request is supported only as of Tarantool 2.3.2.*\n\n*Code*\n\n```php\n$client-\u003eexecute('CREATE TABLE users (\"id\" INTEGER PRIMARY KEY AUTOINCREMENT, \"name\" VARCHAR(50))');\n\n$stmt = $client-\u003eprepare('INSERT INTO users VALUES(null, ?)');\nfor ($i = 1; $i \u003c= 100; ++$i) {\n    $stmt-\u003eexecute(\"name_$i\");\n    // You can also use executeSelect() and executeUpdate(), e.g.:\n    // $lastInsertIds = $stmt-\u003eexecuteUpdate(\"name_$i\")-\u003egetAutoincrementIds();\n}\n$stmt-\u003eclose();\n\n// Note the SEQSCAN keyword in the query. It is available as of Tarantool 2.11.\n// If you are using an older version of Tarantool, omit this keyword.\n$result = $client-\u003eexecuteQuery('SELECT COUNT(\"id\") AS \"cnt\" FROM SEQSCAN users');\n\nprintf(\"Result: %s\\n\", json_encode($result[0]));\n```\n\n*Output*\n\n```\nResult: {\"cnt\":100}\n```\n\u003c/details\u003e\n\n\n### User-defined types\n\nTo store complex structures inside a tuple you may want to use objects:\n\n```php\n$space-\u003einsert([42, Money::EUR(500)]);\n[[$id, $money]] = $space-\u003eselect(Criteria::key([42]));\n```\n\nThis can be achieved by extending the MessagePack type system with your own types. To do this, you need to write \na MessagePack extension that converts your objects into MessagePack structures and back (for more details, read \nthe msgpack.php's [README](https://github.com/rybakit/msgpack.php#custom-types)). Once you have implemented \nyour extension, you should register it with the packer object:\n\n```php\n$packer = PurePacker::fromExtensions(new MoneyExtension());\n$client = new Client(new DefaultHandler($connection, $packer));\n```\n\n\u003e *A working example of using the user-defined types can be found in the [examples](examples/user_defined_type) folder.*\n\n\n## Tests\n\nTo run unit tests:\n\n```bash\nvendor/bin/phpunit --testsuite unit\n```\n\nTo run integration tests:\n\n```bash\nvendor/bin/phpunit --testsuite integration\n```\n\n\u003e *Make sure to start [client.lua](tests/Integration/client.lua) first.*\n\nTo run all tests:\n\n```bash\nvendor/bin/phpunit\n```\n\nIf you already have Docker installed, you can run the tests in a docker container.\nFirst, create a container:\n\n```bash\n./dockerfile.sh | docker build -t client -\n```\n\nThe command above will create a container named `client` with PHP 8.3 runtime.\nYou may change the default runtime by defining the `PHP_IMAGE` environment variable:\n\n```bash\nPHP_IMAGE='php:8.2-cli' ./dockerfile.sh | docker build -t client -\n```\n\n\u003e *See a list of various images [here](https://hub.docker.com/_/php).*\n\n\nThen run a Tarantool instance (needed for integration tests):\n\n```bash\ndocker network create tarantool-php\ndocker run -d --net=tarantool-php -p 3301:3301 --name=tarantool \\\n    -v $(pwd)/tests/Integration/client.lua:/client.lua \\\n    tarantool/tarantool:3 tarantool /client.lua\n```\n\nAnd then run both unit and integration tests:\n\n```bash\ndocker run --rm --net=tarantool-php -v $(pwd):/client -w /client client\n```\n\n\n## Benchmarks\n\nThe benchmarks can be found in the [dedicated repository](https://github.com/tarantool-php/benchmarks).\n\n\n## License\n\nThe library is released under the MIT License. See the bundled [LICENSE](LICENSE) file for details.\n","funding_links":["https://github.com/sponsors/rybakit"],"categories":["Connectors"],"sub_categories":["Administration"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarantool-php%2Fclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftarantool-php%2Fclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarantool-php%2Fclient/lists"}