1. Go to this page and download the library: Download iliaal/pdo_duckdb library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
iliaal / pdo_duckdb example snippets
$db = new PDO('duckdb:/path/to/analytics.duckdb');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->prepare('SELECT region, SUM(amount) AS total FROM sales WHERE year = ? GROUP BY region');
$stmt->execute([2026]);
foreach ($stmt as $row) {
printf("%s: %s\n", $row['region'], $row['total']);
}
// open a database read-only, with a memory cap
$db = new PDO('duckdb:/data/analytics.duckdb;access_mode=read_only;memory_limit=2GB');
// equivalent, via the options array
$db = new PDO('duckdb::memory:', null, null, [
PDO::DUCKDB_ATTR_CONFIG => ['threads' => 4, 'memory_limit' => '2GB'],
]);
$db->exec('CREATE TABLE events (id INTEGER, name VARCHAR, ts TIMESTAMP)');
$app = $db->duckdbAppender('events'); // optional 2nd arg: schema name
foreach ($rows as $r) {
$app->appendRow($r['id'], $r['name'], $r['ts']);
}
$app->flush(); // push buffered rows; appender stays open for more rows
$app->close(); // flush + finalize; further append/flush/close throw