PHPackages                             smeghead/phel-pdo - 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. smeghead/phel-pdo

Abandoned → [phel-lang/phel-pdo](/?search=phel-lang%2Fphel-pdo)Library[Database &amp; ORM](/categories/database)

smeghead/phel-pdo
=================

phel-lang pdo wrapper library.

v0.1.0(1mo ago)58MITShellPHP &gt;=8.4CI passing

Since Apr 23Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/phel-lang/phel-pdo)[ Packagist](https://packagist.org/packages/smeghead/phel-pdo)[ Fund](https://chemaclass.com/sponsor)[ RSS](/packages/smeghead-phel-pdo/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (2)Versions (14)Used By (0)

phel-pdo
========

[](#phel-pdo)

PDO wrapper for [Phel](https://phel-lang.org). Talk to relational databases from Phel without dropping into PHP interop.

Install
-------

[](#install)

```
composer require phel-lang/phel-pdo
```

Requires PHP `>=8.4` and `phel-lang/phel-lang ^0.41`.

Quick start
-----------

[](#quick-start)

```
(require phel.pdo)

(def conn (pdo/connect "sqlite::memory:"))
(pdo/exec conn "create table t1 (id integer primary key autoincrement, name varchar(10))")
(pdo/exec conn "insert into t1 (name) values ('phel'), ('php')")

;; Raw query
(-> (pdo/query conn "select * from t1 where id = 1")
    (pdo/fetch))
;; => {:id 1, :name "phel"}

;; Prepared statement
(-> (pdo/prepare conn "select * from t1 where id = :id")
    (pdo/execute {:id 1})
    (pdo/fetch))
;; => {:id 1, :name "phel"}

;; Insert a row from a map
(pdo/insert conn :t1 {:name "lisp"})
;; => "3"   ; new last-insert-id (string, as PDO reports it)
```

`pdo/fetch` returns the row as a map keyed by column keyword, or `nil` when no rows remain.

With phel-sql
-------------

[](#with-phel-sql)

[phel-sql](https://github.com/phel-lang/phel-sql) is an optional data-driven SQL DSL. It returns `[sql params]` you feed straight into `pdo/prepare` + `pdo/execute`:

```
(let [[query params] (sql/format {:select [:id :name], :from [:users], :where [:= :id 1]})]
  (-> (pdo/prepare conn query)
      (pdo/execute params)
      (pdo/fetch)))
;; => {:id 1, :name "phel"}
```

API
---

[](#api)

All functions live in the `phel.pdo` namespace.

### Connection

[](#connection)

FunctionSignatureDescription`connect``(connect dsn & [username password options])`Open a connection. Throws `PDOException` on failure. Sets `ERRMODE_EXCEPTION` by default.`from-connection``(from-connection pdo & [options])`Wrap an already-open `\PDO` (e.g. a framework/DBAL connection) as-is. `{:apply-defaults true}` sets `ERRMODE_EXCEPTION`.`exec``(exec conn sql)`Execute SQL, return number of affected rows.`query``(query conn sql & [fetch-mode])`Run SQL without placeholders, return a statement.`prepare``(prepare conn sql & [options])`Prepare a statement for later `execute`.`insert``(insert conn table row)`Insert a non-empty `row` map into `table` via a prepared statement and return the new `last-insert-id` (string). Identifiers must match `[A-Za-z_][A-Za-z0-9_]*`.`quote``(quote conn string & [type])`Quote a string for safe embedding in SQL.`last-insert-id``(last-insert-id conn)`ID of the last inserted row, as a string (as PDO reports it).`begin` / `commit` / `rollback``(begin conn)` …Transaction control.`in-transaction``(in-transaction conn)``true` if a transaction is active.`with-transaction``(with-transaction conn & body)`Run `body` in a transaction: commit + return last value, or rollback + re-throw. Runs inline if already in a transaction.`get-attribute` / `set-attribute``(get-attribute handle attr)` / `(set-attribute handle attr value)`PDO attribute access; `handle` is a connection or a statement.`get-available-drivers``(get-available-drivers)`Vector of installed PDO drivers (static; no connection needed).`error-code``(error-code handle)`SQLSTATE string of the last operation; `handle` is a connection or a statement.`error-info``(error-info handle)``[sqlstate driver-code driver-message]`; `handle` is a connection or a statement.### Statement

[](#statement)

Returned by `pdo/query` and `pdo/prepare`.

FunctionSignatureDescription`execute``(execute stmt & [params])`Run a prepared statement. Returns the statement so it threads through `->` / `let`.`fetch``(fetch stmt)`Next row as a map, or `nil` if exhausted.`fetch-all``(fetch-all stmt)`Remaining rows as a vector of maps.`fetch-column``(fetch-column stmt & [column])`Single column from the next row.`fetch-object``(fetch-object stmt & [class-name ctor-args])`Next row as an object (`stdClass` by default, or an instance of `class-name`), or `nil` if exhausted.`statement-seq``(statement-seq stmt)`Lazy seq of the remaining rows as maps, fetched one at a time.`bind-value``(bind-value stmt column value & [type])`Bind a value to a placeholder. Returns the statement.`bind-param``(bind-param stmt column value & [type])`Bind a parameter, applied at execution time. Returns the statement.`column-count``(column-count stmt)`Number of columns in the result set.`row-count``(row-count stmt)`Rows affected by the last DML.`column-meta``(column-meta stmt column)`Metadata map for a 0-indexed column, or `nil` if unavailable.`close-cursor``(close-cursor stmt)`Free the cursor so the statement can be re-executed. Returns the statement.`set-fetch-mode``(set-fetch-mode stmt mode & args)`Set the statement's default fetch mode (extra args match the mode). Returns the statement.`next-rowset``(next-rowset stmt)`Advance to the next rowset of a multi-rowset statement; `false` when none remain.`debug-dump-params``(debug-dump-params stmt)`Dump prepared statement info as a string.Note

Unlike `PDOStatement::execute()` (returns `bool`), `pdo/execute` returns the statement itself so it composes with `->`.

Development
-----------

[](#development)

```
composer install
vendor/bin/phel test
```

Docs
----

[](#docs)

Deeper docs live in [`docs/`](docs/README.md):

- [Getting started](docs/getting-started.md) - install, first query, run tests.
- [Architecture](docs/architecture.md) - `connection` / `statement` design and conventions.
- [Recipes](docs/recipes.md) - transactions, prepared statements, bind types, phel-sql.
- [Troubleshooting](docs/troubleshooting.md) - common errors and fixes.
- [Contributing](docs/contributing.md) - adding wrappers, commits, PRs, releases.

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance92

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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 ~83 days

Recently: every ~179 days

Total

10

Last Release

50d ago

PHP version history (2 changes)v0.0.0PHP &gt;=8.2

v0.1.0PHP &gt;=8.4

### Community

Maintainers

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

---

Top Contributors

[![smeghead](https://avatars.githubusercontent.com/u/112476?v=4)](https://github.com/smeghead "smeghead (36 commits)")[![Chemaclass](https://avatars.githubusercontent.com/u/5256287?v=4)](https://github.com/Chemaclass "Chemaclass (35 commits)")[![jasalt](https://avatars.githubusercontent.com/u/2306521?v=4)](https://github.com/jasalt "jasalt (1 commits)")

---

Tags

phel-langphel-pdopdophel

### Embed Badge

![Health badge](/badges/smeghead-phel-pdo/health.svg)

```
[![Health](https://phpackages.com/badges/smeghead-phel-pdo/health.svg)](https://phpackages.com/packages/smeghead-phel-pdo)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k605.0M6.8k](/packages/doctrine-dbal)[ifsnop/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k6.0M77](/packages/ifsnop-mysqldump-php)[nette/database

💾 Nette Database: layer with a familiar PDO-like API but much more powerful. Building queries, advanced joins, drivers for MySQL, PostgreSQL, SQLite, MS SQL Server and Oracle.

5687.0M262](/packages/nette-database)[dibi/dibi

Dibi is Database Abstraction Library for PHP

5014.0M134](/packages/dibi-dibi)[aura/sql

A PDO extension that provides lazy connections, array quoting, query profiling, value binding, and convenience methods for common fetch styles. Because it extends PDO, existing code that uses PDO can use this without any changes to the existing code.

5892.7M54](/packages/aura-sql)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4883.1M38](/packages/aura-sqlquery)

PHPackages © 2026

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