r4ndsen/sqlite-php

this library will help you deal with sqlite3 databases in php

Maintainers

Package info

github.com/r4ndsen/sqlite-php

pkg:composer/r4ndsen/sqlite-php

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-03-23 07:50 UTC

This package is auto-updated.

Last update: 2026-04-26 08:29:02 UTC


README

High-level helpers for SQLite3 with batteries-included query utilities, schema introspection, and pragma management.

Latest Stable Version Build Status Coverage Status

Requirements

  • PHP 8.2 or newer
  • ext-sqlite3 and ext-mbstring

Installation

Composer

composer require r4ndsen/sqlite-php

From source

git clone https://github.com/r4ndsen/sqlite-php.git
cd sqlite-php
composer install

Quick start

<?php

use r4ndsen\SQLite;
use r4ndsen\SQLite\Column;

$sqlite = new SQLite(':memory:');

$tasks = $sqlite->getTable('tasks');
$tasks
    ->addCreateColumn(Column::createIntegerColumn('id'))
    ->addCreateColumn(Column::createTextColumn('title')->disallowNull())
    ->addCreateColumn(Column::createIntegerColumn('is_done', 0))
    ->createIfNotExists();

$tasks->getDynamicInsertTable()
    ->push(['id' => 1, 'title' => 'Write docs'])
    ->push(['id' => 2, 'title' => 'Tag release', 'is_done' => 1])
    ->commit();

$openTasks = $sqlite->fetchPairs(
    'select id, title from tasks where is_done = :is_done order by id',
    ['is_done' => 0],
);
// [1 => 'Write docs']

foreach ($tasks as $row) {
    // Table implements IteratorAggregate, so you can iterate rows directly
}

$sqlite->validate(); // Runs PRAGMA integrity_check and throws on corruption

Head over to the documentation for more detail on tables, column helpers, pragmas, and query convenience methods.

Development tooling

All just recipes run from the project root (install just from https://github.com/casey/just):

just test        # PHPUnit against the current PHP version
just tests       # PHPUnit against the Docker matrix (PHP 8.2–8.5)
just coverage    # Generates HTML coverage and prints the report path
just infection   # Mutation testing (requires Xdebug)
just stan        # PHPStan static analysis

License

r4ndsen/sqlite-php is licensed under the MIT License. See LICENSE for details.

Changelog

See CHANGELOG for release notes.