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.1(2mo ago)110PHP

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 today

READMEChangelog (10)Dependencies (4)Versions (15)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

37

—

LowBetter than 81% of packages

Maintenance87

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

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

Recently: every ~19 days

Total

14

Last Release

65d ago

### Community

Maintainers

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

---

Top Contributors

[![UniForceMusic](https://avatars.githubusercontent.com/u/51342446?v=4)](https://github.com/UniForceMusic "UniForceMusic (49 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

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

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

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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