PHPackages                             joaojkuligowski/duckdb-pure - 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. joaojkuligowski/duckdb-pure

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

joaojkuligowski/duckdb-pure
===========================

A pure PHP DuckDB Connector.

03PHP

Since Jan 17Pushed 5mo agoCompare

[ Source](https://github.com/joaojkuligowski/duckdb-pure)[ Packagist](https://packagist.org/packages/joaojkuligowski/duckdb-pure)[ RSS](/packages/joaojkuligowski-duckdb-pure/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

DuckDB Pure PHP
===============

[](#duckdb-pure-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/00dd8d730543e08f633dfca66239893b92eb97a0dcd017c0b01f28b4c0a295d4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f616f6a6b756c69676f77736b692f6475636b64622d707572652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/joaojkuligowski/duckdb-pure)[![Tests](https://github.com/joaojkuligowski/duckdb-pure/actions/workflows/main.yml/badge.svg)](https://github.com/joaojkuligowski/duckdb-pure/actions/workflows/main.yml)[![Total Downloads](https://camo.githubusercontent.com/fbe1386246717daea60e56d1724583a3604df389dac66c0e391579b2cf856036/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f616f6a6b756c69676f77736b692f6475636b64622d707572652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/joaojkuligowski/duckdb-pure)

A pure PHP connector for [DuckDB](https://duckdb.org/), the in-process analytical database. This library interacts with the DuckDB CLI application, offering a simple and dependency-light way to run queries from your PHP projects.

Requirements
------------

[](#requirements)

- PHP 8.1+
- [DuckDB CLI](https://duckdb.org/docs/api/cli.html) installed and available in your system's PATH.

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require joaojkuligowski/duckdb-pure
```

Usage
-----

[](#usage)

This library can be used via the `DuckDB` facade, which provides a simple, static interface for interacting with the database.

### Connecting to the Database

[](#connecting-to-the-database)

First, connect to your database file. The connection is managed as a singleton. If the file does not exist, DuckDB will create it.

```
use joaojkuligowski\DuckdbPure\Facades\DuckDB;

DuckDB::connect('/path/to/your/database.duckdb');
```

### Running Queries

[](#running-queries)

Use the `query()` method for `SELECT` statements. This method returns a `DuckDBResult` object.

```
$result = DuckDB::query('SELECT * FROM users WHERE name = :name', [
    'name' => 'Luca'
]);

// Get the results as an array
$users = $result->toArray();

print_r($users);
```

### Executing Statements

[](#executing-statements)

For statements that do not return a result set (e.g., `CREATE`, `INSERT`, `UPDATE`), use the `execute()` method.

```
// Create a table
DuckDB::execute(
    "CREATE TABLE users (id INTEGER, name VARCHAR);"
);

// Insert data
DuckDB::execute(
    "INSERT INTO users VALUES (1, 'Luca'), (2, 'John');"
);
```

### Disconnecting

[](#disconnecting)

The connection can be manually closed if needed.

```
DuckDB::disconnect();
```

### Example

[](#example)

Here is a complete example of how to use the facade:

```
