Phersistence

Tools

The Problem

PHP applications that use MySQL commonly implement their data access layer as a collection of raw SQL queries distributed across the codebase — sometimes in models, sometimes inline in controllers, occasionally in utility functions. This works at first, but it leaves the data model implicit: there is no single place that tells you what fields a "patient" or a "session" or a "record" actually has, what types those fields are, or what validation rules apply before saving.

Existing PHP ORMs address this, but most are either tightly coupled to large frameworks (Laravel's Eloquent requires Laravel; Doctrine's configuration overhead is substantial) or have significant learning curves relative to what a smaller project actually needs. For PHP projects that sit outside those frameworks, the choice has been raw SQL or overengineered dependencies.

Why We Built It

Phersistence was developed for use in CaboLabs' PHP projects where we needed a lightweight ORM that made the data model explicit without requiring a full framework. The projects in question — including internal tooling and the website backend — needed database access, model validation, and relationship handling, but not the full surface area of Laravel or Symfony.

The API was designed to be as simple as possible: define a PHP class that extends the base model, declare your field names, types, and validation rules as class properties, and call save(), find(), or delete(). Phersistence handles the SQL generation, PDO interaction, type conversion, and validation. If validation fails, you get structured error messages back — not an exception mid-save.

Phersistence is also tested using Debbie, the CaboLabs PHP testing library, which made it straightforward to verify ORM behavior during development without setting up a testing framework.

Key Capabilities

What Phersistence provides for PHP MySQL data access.

No framework dependencies

Phersistence has no external dependencies beyond PHP and PDO. It works in any PHP project regardless of what framework (or no framework) is being used.

Declarative model definition

Define models as PHP classes with declared field names, types, and constraints. The data model is explicit and readable in the class definition — not scattered across SQL queries.

CRUD via PDO

Full create, read, update, delete operations generated from the model definition. Uses PDO with prepared statements — no raw SQL string building, no SQL injection risks from parameter handling.

Integrated validation

Validation rules are declared on the model. Before a save operation, Phersistence validates all fields and returns structured error messages if any rules fail — without raising exceptions that interrupt application flow.

Relationship support

Supports has-one and has-many relationships between models. Related records can be loaded and navigated without writing join queries by hand.

Type conversion

Handles PHP-to-MySQL type mapping automatically. Dates, booleans, and numeric types are converted correctly on read and write, based on the field type declared in the model.

Do you have any questions?

Let us know how we can help you.

Company CaboLabs Health Informatics
Address Juan Paullier 995, Montevideo, Uruguay
Phone +598 99 043 145