Download the PHP package piko/db-record without Composer
On this page you can find all versions of the php package piko/db-record. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download piko/db-record
More information about piko/db-record
Files in piko/db-record
Package db-record
Short Description A lightweight Active Record helper built on top of PDO.
License LGPL-3.0-or-later
Homepage https://github.com/piko-framework/db-record
Informations about the package db-record
Piko Db Record
Piko Db Record is a lightweight Active Record implementation built on top of PDO.
It has been tested with:
- SQLite
- MySQL
- PostgreSQL
- MSSQL
Installation
It is recommended to install Piko Db Record with Composer:
Documentation
https://piko-framework.github.io/docs/db-record.html
Usage
First, ensure autoloading is available:
Define your model (attributes)
Optional: map DB columns to different PHP property names
You can then use either mapped property names ($contact->firstName) or underlying column names ($contact->firstname).
Optional: custom cast types (float, decimal, datetime_immutable, datetime_mutable, json)
floatvalues are cast to PHPfloat.decimalvalues are normalized as strings. Withscale, values are rounded/formatted to that precision.datetime_immutablevalues are cast toDateTimeImmutable.datetime_mutablevalues are cast toDateTime.jsonvalues are stored as JSON strings and exposed as PHP arrays.
datetime remains supported as an alias of datetime_immutable for backward compatibility.
Optional: legacy/manual schema (including string primary keys)
With non-integer primary keys, set the key before save() when creating a new row:
Setup database connection
Create a PDO instance and initialize schema:
Recommended: always enable
PDO::ATTR_ERRMODE = PDO::ERRMODE_EXCEPTION. DbRecord throws explicit contextual exceptions when SQL operations fail (PersistenceExceptionfor SQL execution,SchemaExceptionfor mapping/schema issues,RecordNotFoundExceptionfor missing rows). Exception mode still gives the clearest SQL diagnostics.
Perform CRUD operations
Create
Create a new record and save it to the database:
Read
Update
Delete
Known limitations
- Composite primary keys are not supported.
save()updates all mapped columns (no dirty-field tracking yet).- For auto-increment integer primary keys, inserted IDs are filled from
PDO::lastInsertId()when available. - For non-integer (e.g. string) primary keys, your application typically provides the key value.
save()performs an INSERT when the primary key isnullor does not exist in database yet; otherwise it performs an UPDATE.
Running tests
Run full checks (all database targets + coding standards + static analysis):
Run tests for one database only:
Support
If you encounter issues or have questions, feel free to open an issue on GitHub.