{"id":15374316,"url":"https://github.com/yurunsoft/php-tdengine","last_synced_at":"2025-06-28T17:36:14.976Z","repository":{"id":40354692,"uuid":"440367550","full_name":"Yurunsoft/php-tdengine","owner":"Yurunsoft","description":"大数据引擎 TDengine 的 PHP 客户端扩展，支持 Swoole！","archived":false,"fork":false,"pushed_at":"2023-03-21T01:07:18.000Z","size":90,"stargazers_count":77,"open_issues_count":2,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T14:05:42.578Z","etag":null,"topics":["php","swoole","tdengine"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Yurunsoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2021-12-21T02:33:50.000Z","updated_at":"2025-04-06T02:57:31.000Z","dependencies_parsed_at":"2024-01-07T12:52:02.809Z","dependency_job_id":"4a6da93c-b6db-454a-a08d-5d62be8a9b4b","html_url":"https://github.com/Yurunsoft/php-tdengine","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/Yurunsoft/php-tdengine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2Fphp-tdengine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2Fphp-tdengine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2Fphp-tdengine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2Fphp-tdengine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Yurunsoft","download_url":"https://codeload.github.com/Yurunsoft/php-tdengine/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2Fphp-tdengine/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262470368,"owners_count":23316484,"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":["php","swoole","tdengine"],"created_at":"2024-10-01T13:58:20.197Z","updated_at":"2025-06-28T17:36:14.950Z","avatar_url":"https://github.com/Yurunsoft.png","language":"PHP","readme":"# php-tdengine\n\n![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/yurunsoft/php-tdengine/ci/master)\n[![Php Version](https://img.shields.io/badge/php-%3E=7.4-brightgreen.svg)](https://secure.php.net/)\n[![imi License](https://img.shields.io/badge/license-AGPLv3-brightgreen.svg)](https://github.com/yurunsoft/php-tdengine/blob/master/LICENSE)\n\n大数据引擎 [TDengine](https://github.com/taosdata/TDengine) 的 PHP 客户端扩展，还支持了 Swoole 协程化。可以运行在传统 PHP 环境和 Swoole 环境下。\n\n编写了在三大操作系统下的编译及测试用例，保证代码的稳定性和可靠性。\n\n## 环境要求\n\nWindows、Linux、MacOS\n\nPHP \u003e= 7.4\n\nTDengine \u003e= 2.0（已支持 TDengine 3.0）\n\nSwoole \u003e= 4.8 (可选)\n\n## 编译安装\n\n编译前请先安装 [TDengine-client](https://www.taosdata.com/cn/getting-started/#%E9%80%9A%E8%BF%87%E5%AE%89%E8%A3%85%E5%8C%85%E5%AE%89%E8%A3%85) 或者自行编译 TDengine，详见 TDengine 文档：\u003chttps://www.taosdata.com/cn/documentation/connector\u003e\n\n**非 Swoole 环境：**\n\n```shell\nphpize \u0026\u0026 ./configure \u0026\u0026 make -j \u0026\u0026 make install\n```\n\n**手动指定 tdengine 目录：**\n\n```shell\nphpize \u0026\u0026 ./configure --with-tdengine-dir=/usr/local/Cellar/tdengine/2.4.0.0 \u0026\u0026 make -j \u0026\u0026 make install\n```\n\n\u003e `--with-tdengine-dir=` 后跟上 tdengine 目录。\n\u003e 适用于默认找不到的情况，或者 MacOS 系统用户。\n\n**Swoole 环境：**\n\n```shell\nphpize \u0026\u0026 ./configure --enable-swoole \u0026\u0026 make -j \u0026\u0026 make install\n```\n\n**启用扩展：**\n\n方法一：在 `php.ini` 中加入 `extension=tdengine`\n\n方法二：运行带参数 `php -dextension=tdengine test.php`\n\n## PHP 代码编写\n\n\u003e 所有错误都会抛出异常: `TDengine\\Exception\\TDengineException`\n\n**基本：**\n\n```php\nuse TDengine\\Connection;\n\n// 获取扩展版本号\nvar_dump(\\TDengine\\EXTENSION_VERSION);\n\n// 设置客户端选项\n\\TDengine\\setOptions([\n    \\TDengine\\TSDB_OPTION_LOCALE =\u003e 'en_US.UTF-8', // 区域\n    \\TDengine\\TSDB_OPTION_CHARSET =\u003e 'UTF-8', // 字符集\n    \\TDengine\\TSDB_OPTION_TIMEZONE =\u003e 'Asia/Shanghai', // 时区\n    \\TDengine\\TSDB_OPTION_CONFIGDIR =\u003e '/etc/taos', // 配置目录\n    \\TDengine\\TSDB_OPTION_SHELL_ACTIVITY_TIMER =\u003e 3, // shell 活动定时器\n]);\n\n// 获取客户端版本信息\nvar_dump(\\TDengine\\CLIENT_VERSION);\nvar_dump(\\TDengine\\getClientInfo());\n\n// 以下值都是默认值，不改可以不传\n$host = '127.0.0.1';\n$port = 6030;\n$user = 'root';\n$pass = 'taosdata';\n$db = null;\n\n// 实例化\n$connection = new Connection($host, $port, $user, $pass, $db);\n// 连接\n$connection-\u003econnect();\n// 获取连接参数\n$connection-\u003egetHost();\n$connection-\u003egetPort();\n$connection-\u003egetUser();\n$connection-\u003egetPass();\n$connection-\u003egetDb();\n// 获取服务端信息\n$connection-\u003egetServerInfo();\n// 选择默认数据库\n$connection-\u003eselectDb('db1');\n// 关闭连接\n$connection-\u003eclose();\n```\n\n**查询：**\n\n```php\n// 查询\n$resource = $connection-\u003equery($sql); // 支持查询和插入\n// 获取结果集时间戳字段的精度，0 代表毫秒，1 代表微秒，2 代表纳秒\n$resource-\u003egetResultPrecision();\n// 获取所有数据\n$resource-\u003efetch();\n// 获取一行数据\n$resource-\u003efetchRow();\n// 获取字段数组\n$resource-\u003efetchFields();\n// 获取列数\n$resource-\u003egetFieldCount();\n// 获取影响行数\n$resource-\u003eaffectedRows();\n// 获取 SQL 语句\n$resource-\u003egetSql();\n// 获取连接对象\n$resource-\u003egetConnection();\n// 关闭资源（一般不需要手动关闭，变量销毁时会自动释放）\n$resource-\u003eclose();\n```\n\n**参数绑定：**\n\n```php\n// 查询\n$stmt = $connection-\u003eprepare($sql); // 支持查询和插入，参数用?占位\n// 设置表名和标签\n$stmt-\u003esetTableNameTags('表名', [\n    // 支持格式同参数绑定\n    [TDengine\\TSDB_DATA_TYPE_INT, 36],\n]);\n// 绑定参数方法1\n$stmt-\u003ebindParams(\n    // [字段类型, 值]\n    [TDengine\\TSDB_DATA_TYPE_TIMESTAMP, $time1],\n    [TDengine\\TSDB_DATA_TYPE_INT, 36],\n    [TDengine\\TSDB_DATA_TYPE_FLOAT, 44.0],\n);\n// 绑定参数方法2\n$stmt-\u003ebindParams([\n    // ['type' =\u003e 字段类型, 'value' =\u003e 值]\n    ['type' =\u003e TDengine\\TSDB_DATA_TYPE_TIMESTAMP, 'value' =\u003e $time2],\n    ['type' =\u003e TDengine\\TSDB_DATA_TYPE_INT, 'value' =\u003e 36],\n    ['type' =\u003e TDengine\\TSDB_DATA_TYPE_FLOAT, 'value' =\u003e 44.0],\n]);\n// 执行 SQL，返回 Resource，使用方法同 query() 返回值\n$resource = $stmt-\u003eexecute();\n// 获取 SQL 语句\n$stmt-\u003egetSql();\n// 获取连接对象\n$stmt-\u003egetConnection();\n// 关闭（一般不需要手动关闭，变量销毁时会自动释放）\n$stmt-\u003eclose();\n```\n\n**字段类型：**\n\n| 参数名称 | 说明 |\n| ------------ | ------------ \n| `TDengine\\TSDB_DATA_TYPE_NULL` | null |\n| `TDengine\\TSDB_DATA_TYPE_BOOL` | bool |\n| `TDengine\\TSDB_DATA_TYPE_TINYINT` | tinyint |\n| `TDengine\\TSDB_DATA_TYPE_SMALLINT` | smallint |\n| `TDengine\\TSDB_DATA_TYPE_INT` | int |\n| `TDengine\\TSDB_DATA_TYPE_BIGINT` | bigint |\n| `TDengine\\TSDB_DATA_TYPE_FLOAT` | float |\n| `TDengine\\TSDB_DATA_TYPE_DOUBLE` | double |\n| `TDengine\\TSDB_DATA_TYPE_BINARY` | binary |\n| `TDengine\\TSDB_DATA_TYPE_TIMESTAMP` | timestamp |\n| `TDengine\\TSDB_DATA_TYPE_NCHAR` | nchar |\n| `TDengine\\TSDB_DATA_TYPE_UTINYINT` | utinyint |\n| `TDengine\\TSDB_DATA_TYPE_USMALLINT` | usmallint |\n| `TDengine\\TSDB_DATA_TYPE_UINT` | uint |\n| `TDengine\\TSDB_DATA_TYPE_UBIGINT` | ubigint |\n| `TDengine\\TSDB_DATA_TYPE_JSON` | json |\n| `TDengine\\TSDB_DATA_TYPE_VARBINARY` | varbinary |\n| `TDengine\\TSDB_DATA_TYPE_DECIMAL` | decimal |\n| `TDengine\\TSDB_DATA_TYPE_BLOB` | blob |\n| `TDengine\\TSDB_DATA_TYPE_MEDIUMBLOB` | mediumblob |\n| `TDengine\\TSDB_DATA_TYPE_BINARY` | binary |\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyurunsoft%2Fphp-tdengine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyurunsoft%2Fphp-tdengine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyurunsoft%2Fphp-tdengine/lists"}