⌘K ctrl+k
Search Shortcut cmd + k | ctrl + k

PHP Client (Quack Remote Protocol)

The PHP client for DuckDB Quack Remote Protocol is a tertiary client and is maintained by a third-party.

To use the PHP client, follow the instructions below.

The latest version of the client supports DuckDB 2.0.1.

The PHP client for DuckDB Quack Remote Protocol is a pure PHP implementation of the DuckDB Quack Remote Protocol (DuckDB client).
It implements Quack Remote Protocol v3. As a pure PHP implementation, it does not include FFI or C code.
The HTTP transport uses plain PHP streams or the curl extension (curl preferred).

All DuckDB types are supported: Text, Numeric, Date, Time, Interval, JSON, Array, Struct, Map, List, Tuple, Type, Enum, Variant, Geometry, Union, Bitstring, Blob, and Boolean.

Supported PHP versions: 8.2 or newer

GitHub: duckdb-quack-protocol-php

Packagist: duckdb-quack-protocol-php

Installation and Setup (Client)

composer require thomas-0816/duckdb-quack-protocol-php

Installation and Setup (Server)

Start the DuckDB Server:

# localhost, port 9494, HTTP
duckdb --cmd "CALL quack_serve('quack:127.0.0.1:9494', token='secret');"

# public server, port 9495, HTTPs, creates self-signed certificates
duckdb --cmd "CALL quack_serve('quack:0.0.0.0:9495', token='secret', allow_other_hostname=true, disable_ssl=false);"

Read more about Quack Remote Protocol.

Usage Examples

use DuckDB\Quack\QuackClient;

require __DIR__ . '/vendor/autoload.php';

// http-connect-timeout 3s, http-timeout 10s
$db = QuackClient::connect('http://127.0.0.1:9494', 'secret', 3, 10);
$db->execute('CREATE TABLE IF NOT EXISTS table1 (id INTEGER, amount DECIMAL(10, 2), description VARCHAR)');

$db->beginTransaction();
$db->execute('INSERT INTO table1 VALUES (?, ?, ?)', [1, 42.21, 'Hello DuckDB! 🐘 💓 🦆']);
$db->execute('INSERT INTO table1 VALUES (?, ?, ?)', [2, 21.01, 'Hello PHP! 🐘']);
$db->commit();

print_r($db->fetchAll('SELECT * FROM table1'));

# Array
#     [0] => Array
#         [id] => 1
#         [amount] => 42.21
#         [description] => Hello DuckDB! 🐘 💓 🦆
#     [1] => Array
#         [id] => 2
#         [amount] => 21.01
#         [description] => Hello PHP! 🐘

print_r($db->fetchOne('SELECT * FROM table1'));

# Array
#     [id] => 1
#     [amount] => 42.21
#     [description] => Hello DuckDB! 🐘 💓 🦆

print_r($db->fetchValue('SELECT id FROM table1'));

# 1

print_r($db->fetchAllKeyValue('SELECT id, amount FROM table1'));

# Array
#     [1] => 42.21
#     [2] => 21.01

print_r($db->fetchColumn('SELECT description FROM table1'));

# Array
#     [0] => Hello DuckDB! 🐘 💓 🦆
#     [1] => Hello PHP! 🐘

foreach ($db->fetchIterator('SELECT * FROM table1') as $row) {
    print_r($row);
}

# Array
#     [id] => 1
#     [amount] => 42.21
#     [description] => Hello DuckDB! 🐘 💓 🦆
# Array
#     [id] => 2
#     [amount] => 21.01
#     [description] => Hello PHP! 🐘

// named parameter binding
$db->execute("SET VARIABLE foo = 'bar'");
print_r($db->fetchOne('SELECT :id as a, :amount as b, $foo as c', ['id' => 1, 'amount' => 12.34]));

# Array
#     [a] => 1
#     [b] => 12.34
#     [c] => bar

unset($db); // Disconnect

More examples can be found in the readme.

Timeout Configuration

// HTTP connect timeout 3s
// HTTP timeout 10s
$db = QuackClient::connect('http://127.0.0.1:9494', 'secret', 3, 10);

HTTP connect timeout and HTTP timeout (total request time) are applied per request. One query can span over multiple requests.

HTTPs Connections with Self-Signed certificates

use DuckDB\Quack\QuackClient;

require __DIR__ . '/../vendor/autoload.php';

// file location of self-signed public key
$pemFile = getenv('HOME') . '/.duckdb/extension_data/quack/server.pem';

$db = QuackClient::connect('https://localhost:9495', 'secret', 3, 10, [], $pemFile);
echo $db->fetchValue('SELECT 42'), PHP_EOL;

Read more about Quack Security.

Monitoring

use DuckDB\Quack\QuackClient;

require __DIR__ . '/vendor/autoload.php';

$db = QuackClient::connect('http://127.0.0.1:9494', 'secret', 3, 10);

print_r($db->fetchAll('SELECT * FROM quack_active_connections()'));

# Array
#     [0] => Array
#         [server_id] => quack:127.0.0.1:9494
#         [connection_id] => 83FA7408F5D392C23C6CADDDB1F579F2
#         [query] => SELECT * FROM quack_active_connections()
#         [state] => active
#         [query_started_at] => 2026-11-17 02:22:16.402055

License

MIT License

© 2026 DuckDB Foundation, Amsterdam NL
DuckDB Home Code of Conduct Trademark Use Blog