uniforcemusic/php-duckdb-cli 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

uniforcemusic/php-duckdb-cli

Composer 安装命令:

composer require uniforcemusic/php-duckdb-cli

包简介

A DuckDB interface for PHP

README 文档

README

PHP DuckDB CLI is a wrapper around the DuckDB CLI. Not everyone has the ability to enable or install FFI extensions on their system. This library provides a simple solution by interfacing with the command line interface.

Because of the limitations of the command line interface, certain features like prepared statements are emulated.

Setup guide

Install the package using the following command:

composer require uniforcemusic/php-duckdb-cli

Start by creating a new DuckDB instance:

use UniForceMusic\PHPDuckDBCLI\DuckDB;

$duckdb = new DuckDB('database.db');

// Also possible to initialize using static methods
// DuckDB::file('/path/to/file');
// DuckDB::memory();

Argument 1 (file) can be null if you want to use an in memory database.

Argument 2 (binary) can be a custom path to the DuckDB binary.

Executing statements

DuckDB CLI offers 3 ways to execute SQL statements

$duckdb->exec(string $statement): void;
$duckdb->query(string $query): Result;
$duckdb->prepared(string $query, array $params = []): Result;

The result class has three methods:

$result->getRawOutput(): string;
$result->getColumns(): array;
$result->getRows(): array;

To save on performance the output will only be parsed once one of these methods is invoked.

!! The parameters are interpolated in the string, unlike real prepared statements, so beware. !!

Transactions

Like PDO, DuckDB CLI offers 4 methods for managing transactions

$duckdb->beginTransaction(): void;
$duckdb->commitTransaction(): void;
$duckdb->rollbackTransaction(): void;
$duckdb->inTransaction(): bool;

DUCKBOX mode

To add types to the returned results, you can use duckbox mode.

$duckdb->duckboxMode();

This however makes it impossible to retrieve accurate strings since whitespace on the right is trimmed off.

If you wish to get both column types and accurate results, do the following:

$query = 'SELECT * FROM information_schema.tables';

$duckdb->duckboxMode();
$columns = $duckdb->query($query . ' LIMIT 0')->getColumns();

$duckdb->jsonMode();
$rows = $duckdb->query($query)->getRows();

While not efficient, it's DuckDB..... it's gonna be fast regardless.

Integrations

To integratie DuckDB more easily into existing projects, this library offers ready made integrations.

Currently this integration offers an implementation for:

  • [Finished] Sentience Database
  • [WIP] PDO
  • [WIP] mysqli
  • [WIP] SQLite3
  • [Backlog] Laravel

1. Sentience integration

Similar to the Sentience database abstraction, you initialize a database using Database::connect(), or you can use ::fromFile() and ::memory().

Using Sentience in combination with DuckDB gives the advantage of a fluent style querybuilder with a dedicated dialect.

$duckdb = DuckDBDatabase::memory();

$rows = $duckdb->select('orders.csv')
    ->whereGreaterThanOrEquals('total', 50)
    ->orderByDesc('created_at')
    ->execute()
    ->fetchAssocs();

Sentience even takes care of creating sequences when you create a table with a serial column.

$duckdb->createTable('users')
    ->identity('id')
    ->string('email')
    ->primaryKeys(['id'])
    ->uniqueConstraint(['email'], 'users_uniq')
    ->execute();

// First executes:
// CREATE SEQUENCE IF NOT EXISTS "users_id_sequence";

// Then executes:
// CREATE TABLE "users" ("id" INT64 NOT NULL DEFAULT NEXTVAL('users_id_sequence'), "name" VARCHAR(255), PRIMARY KEY ("id"), CONSTRAINT "users_uniq" UNIQUE ("name"));

Tests

To run the tests, run composer test in your console

Notice

There may be response case that this library does not handle. To prevent the system hanging, you can set a timeout.

$duckdb->setTimeout($microseconds): void;
$duckdb->removeTimeout(): void;

This project is not super actively maintained. The inspiration to build this abstraction came from my work on my database abstraction

If anybody wants to clone this project and start a more sophisticated version, feel free!

uniforcemusic/php-duckdb-cli 适用场景与选型建议

uniforcemusic/php-duckdb-cli 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 uniforcemusic/php-duckdb-cli 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 uniforcemusic/php-duckdb-cli 我们能提供哪些服务?
定制开发 / 二次开发

基于 uniforcemusic/php-duckdb-cli 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2026-01-26