r4ndsen / sqlite-php
this library will help you deal with sqlite3 databases in php
1.0.0
2026-03-23 07:50 UTC
Requires
- php: ^8.2
- ext-mbstring: *
- ext-sqlite3: *
- symfony/polyfill-php83: ^1.33
- symfony/polyfill-php84: ^1.33
- symfony/polyfill-php85: ^1.33
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.94
- infection/infection: ^0.31
- php-coveralls/php-coveralls: ^2.9
- phpbench/phpbench: ^1.6
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
- psalm/plugin-phpunit: ^0.19
- rector/rector: ^2.3
- roave/security-advisories: dev-latest
README
High-level helpers for SQLite3 with batteries-included query utilities, schema introspection, and pragma management.
Requirements
- PHP 8.2 or newer
ext-sqlite3andext-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.