PHPackages                             imiphp/imi-tdengine - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. imiphp/imi-tdengine

ActiveLibrary[Database &amp; ORM](/categories/database)

imiphp/imi-tdengine
===================

封装 tdengine 连接池，支持在 imi 框架中使用

v2.1.1(4y ago)568MITPHP

Since Jan 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/imiphp/imi-tdengine)[ Packagist](https://packagist.org/packages/imiphp/imi-tdengine)[ RSS](/packages/imiphp-imi-tdengine/feed)WikiDiscussions 2.0 Synced 3w ago

READMEChangelog (4)Dependencies (8)Versions (6)Used By (0)

imi-tdengine
============

[](#imi-tdengine)

 [ ![imi](https://camo.githubusercontent.com/41475cbf5d4d55194b37404990e3a77279d7bdfa3c1f434431c457f91aafda74/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f696d697068702f696d6940322e302f7265732f6c6f676f2e706e67) ](https://www.imiphp.com)

[![Latest Version](https://camo.githubusercontent.com/da26f39996723e11ebc6e9b50fbc9f55adbbd2e01037275eb95c7b4b1958d8d8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696d697068702f696d692d7464656e67696e652e737667)](https://packagist.org/packages/imiphp/imi-tdengine)[![GitHub Workflow Status (branch)](https://camo.githubusercontent.com/80fe3d386e6842758977b2b3f26b3b408ddb3dfa78e8370deb457a9b7e2c5f6a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f696d697068702f696d692d7464656e67696e652f63692f6d6173746572)](https://camo.githubusercontent.com/80fe3d386e6842758977b2b3f26b3b408ddb3dfa78e8370deb457a9b7e2c5f6a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f696d697068702f696d692d7464656e67696e652f63692f6d6173746572)[![Php Version](https://camo.githubusercontent.com/4a5c2ab20974058a8bab53ecb30ac4c2e6bb961df6229b7386fdc097ab53dfa8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d372e342d627269676874677265656e2e737667)](https://secure.php.net/)[![Swoole Version](https://camo.githubusercontent.com/f4210afc3f396a720a75802010218d847f3ba4f7ae5182c570b1fb2504ec9ec3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73776f6f6c652d2533453d342e372e302d627269676874677265656e2e737667)](https://github.com/swoole/swoole-src)[![imi Doc](https://camo.githubusercontent.com/8a45ed26be92338e9c97fc73a6d772a77ee94fb973e93efc89decb1ea59a8bd7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63732d70617373696e672d677265656e2e737667)](https://doc.imiphp.com/v2.0/)[![imi License](https://camo.githubusercontent.com/88f935c290e6e4efdbf89c57e2dccfe703401825437616aaa3d9b1f0a656e1f3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d756c616e50534c253230312e302d627269676874677265656e2e737667)](https://github.com/imiphp/imi-tdengine/blob/2.0/LICENSE)

介绍
--

[](#介绍)

封装 tdengine 连接池，支持在 imi 框架中使用。

本组件支持 RESTful 和扩展两种方式实现。

扩展安装请移步：

imi 框架交流群：17916227 [![点击加群](https://camo.githubusercontent.com/75b53e353bb9e5064662e185a6d39f4bb88c4e45bd3a1240ddf599525edb6afa/68747470733a2f2f7075622e69647171696d672e636f6d2f7770612f696d616765732f67726f75702e706e67 "点击加群")](https://jq.qq.com/?_wv=1027&k=5wXf4Zq)

使用
--

[](#使用)

引入本组件：`composer require imiphp/imi-tdengine`

### 配置

[](#配置)

项目配置文件：(config/config.php)

```
// Swoole 连接池配置，非 Swoole 不要配
// 连接池必须使用扩展
'pools'    => [
    '连接池名'    => [
        'pool'    => [
            'class'        => \Imi\TDengine\Pool\TDengineExtensionCoroutinePool::class,
            'config'       => [
                'maxResources'    => 10,
                'minResources'    => 0,
            ],
        ],
        'resource'    => [
            'host'            => '127.0.0.1',
            'port'            => 6030,
            'user'            => 'root',
            'password'        => 'taosdata',
            'db'              => 'db_test',
        ],
    ],
],

'beans' => [
    // db 配置
    'TDengine' => [
        'defaultPoolName' => '默认连接名',
        'connections'     => [
            // 扩展配置，不需要可不配
            '连接名1' => [
                'extension'       => true, // 必须设为 true
                'host'            => '127.0.0.1',
                'port'            => 6030,
                'user'            => 'root',
                'password'        => 'taosdata',
                'db'              => 'db_test',
            ],
            // restful 配置，不需要可不配
            '连接名2' => [
                'host'            => '127.0.0.1',
                'hostName'        => '', // 域名，没有可不填
                'port'            => 6041,
                'user'            => 'root',
                'password'        => 'taosdata',
                'db'              => 'db_test'
                'ssl'             => false,
                'timestampFormat' => \Yurun\TDEngine\Constants\TimeStampFormat::LOCAL_STRING,
                'keepAlive'       => true,
            ],
        ],
    ],
],
```

### 模型

[](#模型)

使用参考：

### 连接操作

[](#连接操作)

直接操作连接对象，执行 SQL 语句

#### 获取连接对象

[](#获取连接对象)

```
// 获取默认连接名的连接
$connection = \Imi\TDengine\Pool\TDengine::getConnection();
// 获取指定连接名的连接
$connection = \Imi\TDengine\Pool\TDengine::getConnection('连接名123');
// 如果是扩展，$connection 类型为 \TDengine\Connection
// 如果是 restful，$connection 类型为 \Yurun\TDEngine\Client
```

#### 扩展用法

[](#扩展用法)

**查询：**

```
// 查询
$resource = $connection->query($sql); // 支持查询和插入
// 获取结果集时间戳字段的精度，0 代表毫秒，1 代表微秒，2 代表纳秒
$resource->getResultPrecision();
// 获取所有数据
$resource->fetch();
// 获取一行数据
$resource->fetchRow();
// 获取字段数组
$resource->fetchFields();
// 获取列数
$resource->getFieldCount();
// 获取影响行数
$resource->affectedRows();
// 获取 SQL 语句
$resource->getSql();
// 获取连接对象
$resource->getConnection();
// 关闭资源（一般不需要手动关闭，变量销毁时会自动释放）
$resource->close();
```

**参数绑定：**

```
// 查询
$stmt = $connection->prepare($sql); // 支持查询和插入，参数用?占位
// 绑定参数方法1
$stmt->bindParams(
    // [字段类型, 值]
    [TDengine\TSDB_DATA_TYPE_TIMESTAMP, $time1],
    [TDengine\TSDB_DATA_TYPE_INT, 36],
    [TDengine\TSDB_DATA_TYPE_FLOAT, 44.5],
);
// 绑定参数方法2
$stmt->bindParams([
    // ['type' => 字段类型, 'value' => 值]
    ['type' => TDengine\TSDB_DATA_TYPE_TIMESTAMP, 'value' => $time2],
    ['type' => TDengine\TSDB_DATA_TYPE_INT, 'value' => 36],
    ['type' => TDengine\TSDB_DATA_TYPE_FLOAT, 'value' => 44.5],
]);
// 执行 SQL，返回 Resource，使用方法同 query() 返回值
$resource = $stmt->execute();
// 获取 SQL 语句
$stmt->getSql();
// 获取连接对象
$stmt->getConnection();
// 关闭（一般不需要手动关闭，变量销毁时会自动释放）
$stmt->close();
```

**字段类型：**

参数名称说明`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_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#### restful 用法

[](#restful-用法)

```
// 通过 sql 方法执行 sql 语句
var_dump($connection->sql('create database if not exists db_test'));
var_dump($connection->sql('show databases'));
var_dump($connection->sql('create table if not exists db_test.tb (ts timestamp, temperature int, humidity float)'));
var_dump($connection->sql(sprintf('insert into db_test.tb values(%s,%s,%s)', time() * 1000, mt_rand(), mt_rand() / mt_rand())));

$result = $connection->sql('select * from db_test.tb');

$result->getResponse(); // 获取接口原始返回数据

// 获取列数据
foreach ($result->getColumns() as $column)
{
    $column->getName(); // 列名
    $column->getType(); // 列类型值
    $column->getTypeName(); // 列类型名称
    $column->getLength(); // 类型长度
}

// 获取数据
foreach ($result->getData() as $row)
{
    echo $row['列名']; // 经过处理，可以直接使用列名获取指定列数据
}

$result->getStatus(); // 告知操作结果是成功还是失败；同接口返回格式

$result->getHead(); // 表的定义，如果不返回结果集，则仅有一列“affected_rows”。（从 2.0.17 版本开始，建议不要依赖 head 返回值来判断数据列类型，而推荐使用 column_meta。在未来版本中，有可能会从返回值中去掉 head 这一项。）；同接口返回格式

$result->getRow(); // 表明总共多少行数据；同接口返回格式
```

版权信息
----

[](#版权信息)

imi 遵循 木兰宽松许可证(Mulan PSL v2) 开源协议发布，并提供免费使用。

捐赠
--

[](#捐赠)

[![捐赠](https://camo.githubusercontent.com/d6289b746e049310225a52ee7d4f9aab71cf9df63a3341cb037e7ec09b31ea1f/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f696d697068702f696d6940322e302f7265732f7061792e706e67)](https://camo.githubusercontent.com/d6289b746e049310225a52ee7d4f9aab71cf9df63a3341cb037e7ec09b31ea1f/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f696d697068702f696d6940322e302f7265732f7061792e706e67)

开源不求盈利，多少都是心意，生活不易，随缘随缘……

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~57 days

Recently: every ~72 days

Total

6

Last Release

1335d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f917bb42280d114c53cebadc2942a13ee03abe14971089f88895e266d637169?d=identicon)[Yurunsoft](/maintainers/Yurunsoft)

---

Top Contributors

[![Yurunsoft](https://avatars.githubusercontent.com/u/20104656?v=4)](https://github.com/Yurunsoft "Yurunsoft (16 commits)")

---

Tags

phpswooletdengine

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/imiphp-imi-tdengine/health.svg)

```
[![Health](https://phpackages.com/badges/imiphp-imi-tdengine/health.svg)](https://phpackages.com/packages/imiphp-imi-tdengine)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
