151 lines
4.3 KiB
Plaintext
151 lines
4.3 KiB
Plaintext
---
|
|
sidebar_label: PHP
|
|
title: PHP Client Library
|
|
slug: /tdengine-reference/client-libraries/php
|
|
---
|
|
|
|
`php-tdengine` is a PHP connector extension contributed by the community, which also specifically supports Swoole coroutine.
|
|
|
|
The PHP connector depends on the TDengine client driver.
|
|
|
|
Project address: [https://github.com/Yurunsoft/php-tdengine](https://github.com/Yurunsoft/php-tdengine)
|
|
|
|
After installing the TDengine server or client, `taos.h` is located at:
|
|
|
|
- Linux: `/usr/local/taos/include`
|
|
- Windows: `C:\TDengine\include`
|
|
- macOS: `/usr/local/include`
|
|
|
|
The dynamic library of the TDengine client driver is located at:
|
|
|
|
- Linux: `/usr/local/taos/driver/libtaos.so`
|
|
- Windows: `C:\TDengine\taos.dll`
|
|
- macOS: `/usr/local/lib/libtaos.dylib`
|
|
|
|
## Supported Platforms
|
|
|
|
- Windows, Linux, macOS
|
|
- PHP >= 7.4
|
|
- TDengine >= 2.0
|
|
- Swoole >= 4.8 (optional)
|
|
|
|
## Supported Versions
|
|
|
|
The version number of the TDengine client driver has a strong correspondence with the version number of the TDengine server. It is recommended to use a client driver that is exactly the same as the TDengine server. Although lower version client drivers can be compatible with higher version servers if the first three segments of the version number match (only the fourth segment differs), this is not recommended. It is strongly advised not to use a higher version client driver to access a lower version server.
|
|
|
|
## Installation Steps
|
|
|
|
### Install TDengine Client Driver
|
|
|
|
For installation of the TDengine client driver, please refer to the [Installation Guide](../#installing-client-drivers).
|
|
|
|
### Compile and Install php-tdengine
|
|
|
|
**Download the code and unzip it:**
|
|
|
|
```shell
|
|
curl -L -o php-tdengine.tar.gz https://github.com/Yurunsoft/php-tdengine/archive/refs/tags/v1.0.2.tar.gz \
|
|
&& mkdir php-tdengine \
|
|
&& tar -xzf php-tdengine.tar.gz -C php-tdengine --strip-components=1
|
|
```
|
|
|
|
Version `v1.0.2` can be replaced with any newer version, which can be found in the [TDengine PHP Connector Release History](https://github.com/Yurunsoft/php-tdengine/releases).
|
|
|
|
**Non-Swoole Environment:**
|
|
|
|
```shell
|
|
phpize && ./configure && make -j && make install
|
|
```
|
|
|
|
**Manually Specify the TDengine Directory:**
|
|
|
|
```shell
|
|
phpize && ./configure --with-tdengine-dir=/usr/local/Cellar/tdengine/3.0.0.0 && make -j && make install
|
|
```
|
|
|
|
Follow `--with-tdengine-dir=` with the TDengine directory.
|
|
This is applicable for situations where the default cannot be found or for macOS users.
|
|
|
|
**Swoole Environment:**
|
|
|
|
```shell
|
|
phpize && ./configure --enable-swoole && make -j && make install
|
|
```
|
|
|
|
**Enable the Extension:**
|
|
|
|
Method 1: Add `extension=tdengine` to `php.ini`
|
|
|
|
Method 2: Run with the parameter `php -dextension=tdengine test.php`
|
|
|
|
## Example Programs
|
|
|
|
This section shows example code for common access methods to access the TDengine cluster using the client driver.
|
|
|
|
All errors will throw exceptions: `TDengine\Exception\TDengineException`
|
|
|
|
### Establish Connection
|
|
|
|
<details>
|
|
<summary>Establish Connection</summary>
|
|
|
|
```c
|
|
{{#include docs/examples/php/connect.php}}
|
|
```
|
|
|
|
</details>
|
|
|
|
### Insert Data
|
|
|
|
<details>
|
|
<summary>Insert Data</summary>
|
|
|
|
```c
|
|
{{#include docs/examples/php/insert.php}}
|
|
```
|
|
|
|
</details>
|
|
|
|
### Synchronous Query
|
|
|
|
<details>
|
|
<summary>Synchronous Query</summary>
|
|
|
|
```c
|
|
{{#include docs/examples/php/query.php}}
|
|
```
|
|
|
|
</details>
|
|
|
|
### Parameter Binding
|
|
|
|
<details>
|
|
<summary>Parameter Binding</summary>
|
|
|
|
```c
|
|
{{#include docs/examples/php/insert_stmt.php}}
|
|
```
|
|
|
|
</details>
|
|
|
|
## Constants
|
|
|
|
| Constant | Description |
|
|
| ----------------------------------- | ----------- |
|
|
| `TDengine\TSDB_DATA_TYPE_NULL` | null |
|
|
| `TDengine\TSDB_DATA_TYPE_BOOL` | bool |
|
|
| `TDengine\TSDB_DATA_TYPE_TINYINT` | tinyint |
|
|
| `TDengine\TSDB_DATA_TYPE_SMALLINT` | smallint |
|
|
| `TDengine\TSDB_DATA_TYPE_INT` | int |
|
|
| `TDengine\TSDB_DATA_TYPE_BIGINT` | bigint |
|
|
| `TDengine\TSDB_DATA_TYPE_FLOAT` | float |
|
|
| `TDengine\TSDB_DATA_TYPE_DOUBLE` | double |
|
|
| `TDengine\TSDB_DATA_TYPE_BINARY` | binary |
|
|
| `TDengine\TSDB_DATA_TYPE_VARBINARY` | varbinary |
|
|
| `TDengine\TSDB_DATA_TYPE_TIMESTAMP` | timestamp |
|
|
| `TDengine\TSDB_DATA_TYPE_NCHAR` | nchar |
|
|
| `TDengine\TSDB_DATA_TYPE_UTINYINT` | utinyint |
|
|
| `TDengine\TSDB_DATA_TYPE_USMALLINT` | usmallint |
|
|
| `TDengine\TSDB_DATA_TYPE_UINT` | uint |
|
|
| `TDengine\TSDB_DATA_TYPE_UBIGINT` | ubigint |
|