PHPackages                             intermaterium/duckeh - 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. intermaterium/duckeh

ActivePhp-ext[Database &amp; ORM](/categories/database)

intermaterium/duckeh
====================

PHP extension for DuckDB

0.7.2(1mo ago)059↓84.3%MITCPHP &gt;=8.1CI failing

Since Mar 27Pushed 1mo agoCompare

[ Source](https://github.com/chrisBirmingham/duckeh)[ Packagist](https://packagist.org/packages/intermaterium/duckeh)[ RSS](/packages/intermaterium-duckeh/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (18)Used By (0)

Duckeh - DuckDB for PHP
=======================

[](#duckeh---duckdb-for-php)

A PHP extension for the [DuckDB](https://duckdb.org/) API

This is a fork of [Daniel Hernández Marín](https://github.com/dhernandez) original work found [here](https://github.com/satur-io/duckdb)

Caution

This project is in an early development stage and there are probably a tonne of bugs. Nevertheless, any contribution will be welcome.

Prerequisites
-------------

[](#prerequisites)

- libduckdb 1.5.0 and above
- PHP 8.1 and above

Installation (PIE)
------------------

[](#installation-pie)

You can install this extension using [PIE](https://github.com/php/pie):

```
pie install intermaterium/duckeh
```

Installation (Build from source)
--------------------------------

[](#installation-build-from-source)

You can also use the old phpize method to install the extension

```
git clone --recursive --depth=1 https://github.com/chrisBirmingham/duckeh.git
cd duckeh
phpize
./configure
make
make install
```

Configuration
-------------

[](#configuration)

Then enable the extension, add this to your PHP INI file

```
extension=duckdb
```

Usage
-----

[](#usage)

### Creation

[](#creation)

A new in-memory database can be created like so:

```
$db = new \DuckDB\DuckDB();
```

You can attach to a store by specifying a path like so.

```
$db = new \DuckDB\DuckDB(__DIR__ '/Star_Trek-Season_1.csv');
```

A `ConnectionException` is thrown if the class fails to initialise.

### Running Queries

[](#running-queries)

#### Simple

[](#simple)

You can run queries via the `query` method:

```
$db = new \DuckDB\DuckDB();
$res = $db->query('SELECT * FROM duck');
```

The query method returns a `Result` class or throws a `QueryException` if the query fails.

#### Prepared Statements

[](#prepared-statements)

Prepared statements are created via the `prepare` method:

```
$db = new \DuckDB\DuckDB();

# Named (`$1`, `$quack`) and unnamed (`?`) parameters are supported.
$stmt = $db->prepare('SELECT * FROM duck where quack = $1');

# Bind a variable to the parameter
$stmt->bindParam(1, "honk");

# Execute the prepared statement
$res = $stmt->execute();
```

On success, a `Result` class is returned otherwise a `QueryException` is thrown if the query fails. If a bound parameter doesn't exist or the value provided to the bound parameter isn't a scalar value, an `InvalidArgumentException` is thrown

### Results

[](#results)

#### Fetch Methods

[](#fetch-methods)

These methods map closely to the pdo statement methods of the same name. The `fetch` method will keep on returning data until it reaches the end of the returned data where it will return false. The `fetchAll` method will collect all the data and return it as one big array.

Both methods return each row as an associative array with the column name as the key and the values are mapped directly to PHP types.

```
$db = new \DuckDB\DuckDB(__DIR__ . '/Star_Trek-Season_1.csv');
$res = $db->query('SELECT episode_num FROM "Star_Trek-Season_1" limit 10');

while ($row = $res->fetch()) {
    echo $row['episode_num'] . "\n" ;
}

$db = new \DuckDB\DuckDB(__DIR__ . '/Star_Trek-Season_1.csv');
$res = $db->query('SELECT episode_num FROM "Star_Trek-Season_1" limit 10')->fetchAll();

foreach ($res as $row) {
    echo $row['episode_num'] . "\n" ;
}
```

### Appender

[](#appender)

This extension provides an interface to the Appender feature provided by duckdb. The duckdb Appender is best suited for fast data loading opposed to inserting multiple rows via an INSERT query.

You can create an appender via the `append` method:

```
$db = new \DuckDB\DuckDB();
$appender = $db->append('table');
```

You can then insert a row `appendRow` method:

```
$appender->appendRow([1, 'Duck']);

$db->query('SELECT * FROM people')->print();

for ($i = 2; $i appendRow([$i, 'Duck' . $i]);
}
```

Rows aren't automatically appended to the table. You can explicitly flush the rows to the table via the `flush` method, otherwise the rows will either be flushed when an internal buffer is filled up or when the appender is cleaned up via the garbage collector.

To control when the appender implicitly flushes it's records, you can set the ini `duckdb.appender_max_buffer`. This controls the max number of records inside the appenders internal buffer before it flushes to the table. The default value is 1000 records.

If you want to clear the appended rows, you can call the `clear` method.

If you want to use the default value for an column in the append statement, you can now create a new `DefaultValue` class and use that where needed.

Caution

Care should be taken when inserting rows into the appender. Should an exception be thrown because of type mismatches, the appender can be left in an incomplete state. In such a situation, it's best that you call the clear method

### Timezone Considerations

[](#timezone-considerations)

For some reason, when the duckdb api retrieves a timestamp field, if the field contains timezone information, it will instead return's a timestamp datatype thus losing the timezone information. This problem does not affect the Time field type.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance94

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 53.5% 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 ~20 days

Total

16

Last Release

30d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/605c5ba17b9ede3481247c152615eae793b42714b4c5a6d40c2afa0e341f97ca?d=identicon)[intermaterium](/maintainers/intermaterium)

---

Top Contributors

[![chrisBirmingham](https://avatars.githubusercontent.com/u/6173078?v=4)](https://github.com/chrisBirmingham "chrisBirmingham (69 commits)")[![dhernandez](https://avatars.githubusercontent.com/u/1096670?v=4)](https://github.com/dhernandez "dhernandez (60 commits)")

### Embed Badge

![Health badge](/badges/intermaterium-duckeh/health.svg)

```
[![Health](https://phpackages.com/badges/intermaterium-duckeh/health.svg)](https://phpackages.com/packages/intermaterium-duckeh)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.8k117.8M121](/packages/jdorn-sql-formatter)[backup-manager/backup-manager

A framework agnostic database backup manager with user-definable procedures and support for S3, Dropbox, FTP, SFTP, and more with drivers for popular frameworks.

1.7k1.6M11](/packages/backup-manager-backup-manager)[propel/propel1

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

8351.6M88](/packages/propel-propel1)[insolita/yii2-migration-generator

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

108508.0k5](/packages/insolita-yii2-migration-generator)[xpdo/xpdo

A PDO-based Object/Relational Bridge Library

7088.4k4](/packages/xpdo-xpdo)[voku/session2db

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

3220.0k](/packages/voku-session2db)

PHPackages © 2026

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