PHPackages                             uniforcemusic/php-duckdb-cli - 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. uniforcemusic/php-duckdb-cli

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

uniforcemusic/php-duckdb-cli
============================

A DuckDB interface for PHP

v1.5.0(2mo ago)17PHP

Since Jan 29Pushed 2mo agoCompare

[ Source](https://github.com/UniForceMusic/php-duckdb-cli)[ Packagist](https://packagist.org/packages/uniforcemusic/php-duckdb-cli)[ RSS](/packages/uniforcemusic-php-duckdb-cli/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (2)Versions (14)Used By (0)

PHP DuckDB CLI
==============

[](#php-duckdb-cli)

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
-----------

[](#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
--------------------

[](#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
------------

[](#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
------------

[](#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
------------

[](#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

[](#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
-----

[](#tests)

To run the tests, run `composer test` in your console

Notice
------

[](#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](https://github.com/Sentience-Framework/database)

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

###  Health Score

38

—

LowBetter than 84% of packages

Maintenance90

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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 ~2 days

Total

13

Last Release

75d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9369c097bedc3dc3625200ccd56dc12388bdd7349618ea93d04b4fdc35e99e22?d=identicon)[UniForceMusic](/maintainers/UniForceMusic)

---

Top Contributors

[![UniForceMusic](https://avatars.githubusercontent.com/u/51342446?v=4)](https://github.com/UniForceMusic "UniForceMusic (48 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/uniforcemusic-php-duckdb-cli/health.svg)

```
[![Health](https://phpackages.com/badges/uniforcemusic-php-duckdb-cli/health.svg)](https://phpackages.com/packages/uniforcemusic-php-duckdb-cli)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M540](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M208](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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