PHPackages                             kiss-php/tables - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. kiss-php/tables

ActiveLibrary[Database &amp; ORM](/categories/database)

kiss-php/tables
===============

Kiss ORM for php.

0.1.1(1mo ago)013MITPHP

Since Jan 3Pushed 1mo agoCompare

[ Source](https://github.com/kiss-php/tables)[ Packagist](https://packagist.org/packages/kiss-php/tables)[ RSS](/packages/kiss-php-tables/feed)WikiDiscussions master Synced today

READMEChangelog (3)DependenciesVersions (6)Used By (0)

Tables
======

[](#tables)

Tables is a small PHP ORM-like library that maps simple `.tbl` files to PDO rows. It is designed for quick projects where table definitions live beside the code and the library can create or repair the schema when a table or column is missing.

Install
-------

[](#install)

```
composer require kiss-php/tables
```

Or, inside this repository:

```
composer dump-autoload
```

Configuration
-------------

[](#configuration)

Connections are read from `$_ENV`. The default connection uses the `DB_` prefix:

```
$_ENV['DB_TYPE'] = 'sqlite';
$_ENV['DB_PATH'] = __DIR__ . '/db/app.sqlite';
```

MySQL is also supported:

```
$_ENV['DB_TYPE'] = 'mysql';
$_ENV['DB_HOST'] = 'localhost';
$_ENV['DB_USER'] = 'root';
$_ENV['DB_PASS'] = '';
$_ENV['DB_DTBS'] = 'app';
$_ENV['DB_PORT'] = '3306';
```

Named connections use `DB__`, for example `DB_LITLE_TYPE` and `DB_LITLE_PATH`, then pass the flag to `TablesManager` or `Row` methods.

Table Definitions
-----------------

[](#table-definitions)

Create `.tbl` files in a folder, one file per table:

```
# Tables/User.tbl
user[varchar(90)]:unique
mail[varchar(255)]
active[boolean](true)
phone[varchar(25)]:null
profile@UserProfile.user_id
```

Supported syntax:

- `field[type]`
- `field[type](default)`
- `field[type]:null:unique:unsigned:zero:binary:increment`
- `field[type]$OtherTable.id` for a foreign key stored on the current table
- `field@OneTable.current_id` for a virtual one-to-one lookup
- `field@ManyTable.current_id` for a virtual one-to-many lookup
- `legacy_id=OtherTable.id` for older relation definitions

Every table gets an auto-increment `id` column automatically.

Usage
-----

[](#usage)

```
require 'vendor/autoload.php';

use Kiss\Tables\TablesManager;

TablesManager::setFolder(__DIR__ . '/Tables');
TablesManager::ensureSchema();

$user = TablesManager::new('User');
$user->setUser('ada');
$user->setMail('ada@example.test');
$user->persist();

$found = TablesManager::getOne('User', ['user' => 'ada']);
$found->setMail('ada@lovelace.test');
$found->persist();
```

Rows expose dynamic getters and setters. CamelCase method names are converted to snake\_case database columns:

```
$user->setMailVerified(true); // mail_verified
$user->getMailVerified();
```

Schema Repair
-------------

[](#schema-repair)

`persist()` and `get()` recover from missing tables by creating the table from its `.tbl` definition. `persist()` can also add missing columns and retry the operation. This auto-repair behavior is enabled by default because it is the core workflow of the library.

You can disable it for stricter environments:

```
TablesManager::setAutoRepair(false);
```

For explicit setup, call:

```
TablesManager::ensureSchema();
```

Rollback
--------

[](#rollback)

Rows changed through `persist()` or `delete()` are tracked. Calling:

```
TablesManager::rollback();
```

restores updated/deleted rows or removes rows inserted during the current process.

History Logs
------------

[](#history-logs)

Tables keeps a small in-memory history. It stores SQL parameters as they are provided. This keeps the library small and predictable, but it also means you should not print or export history in production unless you are comfortable with the values it contains.

You can route logs wherever you want with an optional callback:

```
use Kiss\Tables\History;

History::callback(function (array $entry) {
    // Send to Monolog, a PSR-3 logger, stdout, a file, etc.
    // $entry contains: type, message, context.
    // Redact or drop sensitive values here if your app needs it.
});
```

Database exceptions are logged as sanitized error events with the exception class and code, not the raw database error message.

Security and Operational Notes
------------------------------

[](#security-and-operational-notes)

Tables is a lightweight library, not a full application security layer. Keep these points in mind when using it:

- Treat `.tbl` files as trusted code. They drive table names, column names, column types, defaults and relations. Do not load table definition folders that can be edited by end users.
- Auto-repair is enabled by default and may run `CREATE TABLE` or `ALTER TABLE`during normal reads/writes. This is useful for KISS-style development, but it means the database user needs DDL permissions. In stricter deployments, run `TablesManager::ensureSchema()` during deploy and then call `TablesManager::setAutoRepair(false)`.
- `History` stores SQL parameters as provided. Do not call `History::printAll()`or export `History::getAll()` in production unless your application has already removed or filtered sensitive values.
- If you use `History::callback()`, the callback belongs to your application: redact sensitive data there, send logs to your preferred logger, and avoid throwing from the callback unless you intentionally want logging failures to interrupt database operations.
- `TablesManager::rollback()` is an in-memory convenience helper, not a database transaction. It is useful for simple undo flows in the current PHP process, but it does not provide ACID guarantees or protect concurrent writes.
- Database credentials should come from environment/configuration management. Do not hardcode real credentials in examples, scripts or committed files.

Smoke Test
----------

[](#smoke-test)

Run the SQLite smoke test:

```
php tests/smoke.php
```

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance90

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~165 days

Total

4

Last Release

51d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/61379065?v=4)[A.Grandes.R](/maintainers/AGrandesR)[@AGrandesR](https://github.com/AGrandesR)

---

Top Contributors

[![AGrandesR](https://avatars.githubusercontent.com/u/61379065?v=4)](https://github.com/AGrandesR "AGrandesR (10 commits)")

### Embed Badge

![Health badge](/badges/kiss-php-tables/health.svg)

```
[![Health](https://phpackages.com/badges/kiss-php-tables/health.svg)](https://phpackages.com/packages/kiss-php-tables)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
