ElephpantDB: Full SQL Database in One PHP File
ElephpantDB is an experimental SQL database implemented in a single PHP file, supporting CREATE TABLE, SELECT, UPDATE, DELETE, indexes, prepared statements, an append-only heap with crash recovery, hash indexes, and an optional HTTP JSON endpoint, running on PHP 8.3+.
Overview
ElephpantDB is an experimental SQL database implemented in a single PHP file by Anton Medvedev. It provides a complete SQL engine capable of creating tables, querying, updating, and deleting data, all within a standalone PHP script that runs on PHP 8.3 or later (64-bit required). The project is available on GitHub at https://github.com/antonmedv/elephpantdb.
Supported SQL Features
CREATE TABLE, SELECT, UPDATE, DELETE Indexes (hash-based) INSERT with prepared parameters
Sorting ( ORDER BY) and limiting ( LIMIT)
Storage Architecture
Data rows are stored in an append-only heap where each record is identified by its byte offset. Updates write a new version of the row; deletes mark the old record as stale. A VACUUM command eventually reclaims space by cleaning up historical versions.
Indexing and Reliability
The heap remains the source of truth, while indexes are treated as rebuildable caches. This design provides a healthy balance: the heap stores facts, and indexes accelerate lookups without guaranteeing absolute correctness. The engine also includes file locking, checksums, and crash recovery to ensure durability.
Usage Options
ElephpantDB can be used directly from PHP code or exposed as a JSON-over-HTTP endpoint. The HTTP interface accepts SQL statements and parameters via POST requests, with optional token authentication for basic access control.
Requirements and Design Philosophy
The engine requires PHP 8.3+ (64-bit). The single-file distribution is partly for convenience and partly because splitting the engine into modules was considered too adventurous and irresponsible at this experimental stage.
Production Readiness
The author advises against migrating large production systems to ElephpantDB at version 0.1.0. It is suitable for storing a few important records or unlimited unimportant data, and serves as an educational example of a database engine written in PHP.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
