Skip to main content

ElephpantDB: A Database in One PHP File

· 2 min read
Anton Medvedev
Deployer Maintainer

Today I’m releasing ElephpantDB, a small SQL database written entirely in PHP and shipped as a single file.

Why? Because sometimes you look at a normal application stack and think: “This has far too few opportunities for surprise.”

ElephpantDB supports the familiar essentials: CREATE TABLE, INSERT, SELECT, UPDATE, DELETE, indexes, prepared parameters, ordering, limits, and even VACUUM. In other words, it contains enough SQL to store your users, retrieve your users, accidentally update all your users, and then carefully read the documentation.

Under the surface, rows live in an append-only heap, where each record is identified by its byte offset. Updates write a new version of a row, deletes mark old records as dead, and VACUUM eventually cleans up the historical evidence.

It also has file locking, checksums, crash recovery, and hash indexes. The heap remains the source of truth, while indexes are treated as rebuildable caches. This is a healthy relationship: the heap keeps the facts, and the index helps find them quickly without pretending it is always right.

You can use ElephpantDB directly from PHP or expose it as a small JSON-over-HTTP endpoint. The HTTP interface accepts SQL and parameters in a POST request, and optional token authentication is available for people who prefer their arbitrary SQL endpoints with at least one locked door.

The entire engine runs on PHP 8.3 or newer and requires a 64-bit build. It ships as one file, partly for convenience and partly because splitting a database engine into sensible modules sounded dangerously responsible.

Should you immediately move your largest production system to ElephpantDB?

Probably not.

Should you download it, create a table, insert a few rows, inspect the binary files, and enjoy the fact that PHP is now responsible for even more of your infrastructure?

Absolutely.

ElephpantDB 0.1.0 is available now. It is small, experimental, surprisingly serious inside, and ready to store at least several important things, or an unlimited number of unimportant ones.

https://github.com/antonmedv/elephpantdb