PHPackages                             detain/dbrel-data-php - 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. detain/dbrel-data-php

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

detain/dbrel-data-php
=====================

PHP backend data provider for database relationship visualization. Collects customer data across multiple databases and computes relationship matches for consumption by dbrel-viz.

v1.0.0(1mo ago)1543↓50%MITPHPPHP &gt;=7.4

Since Apr 19Pushed 1mo agoCompare

[ Source](https://github.com/detain/dbrel-data-php)[ Packagist](https://packagist.org/packages/detain/dbrel-data-php)[ Docs](https://github.com/detain/dbrel-data-php)[ RSS](/packages/detain-dbrel-data-php/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

dbrel-data-php
==============

[](#dbrel-data-php)

### PHP backend that turns your MySQL schema into an interactive relationship graph.

[](#php-backend-that-turns-your-mysql-schema-into-an-interactive-relationship-graph)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4a0004837408af2fb09a16539ad402f027b5de41755be4dc87dc480f4f8fbb7e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64657461696e2f646272656c2d646174612d7068702e7376673f7374796c653d666c61742d73717561726526636f6c6f723d627269676874677265656e)](https://packagist.org/packages/detain/dbrel-data-php)[![Total Downloads](https://camo.githubusercontent.com/92fbd0455652567b14d69d993197039eeff51a8c7280c76acfe7e98a4a8a169c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64657461696e2f646272656c2d646174612d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/detain/dbrel-data-php)[![PHP Version](https://camo.githubusercontent.com/b881accd29da28909436866f60fd89791d2f2dddbf0193570754889679d41527/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f64657461696e2f646272656c2d646174612d7068703f7374796c653d666c61742d737175617265)](https://www.php.net/)[![License](https://camo.githubusercontent.com/bf5618615c6c409096df8b2b97be8548f6727064beb213eef2afabbb9c383b2d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f64657461696e2f646272656c2d646174612d7068702e7376673f7374796c653d666c61742d73717561726526636f6c6f723d626c7565)](./LICENSE)[![Build Status](https://camo.githubusercontent.com/2b36d174ef00f44d8dfcc0d4122ab61ea239d87ac900ff4211ff3ac206986778/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c642d70617373696e672d737563636573733f7374796c653d666c61742d737175617265)](#)[![Code Coverage](https://camo.githubusercontent.com/b1774e4a8b58fdd7ca75e8293f94c4cd31e1bcd323e24a2518aa864d0cb4b443/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d39352532352d627269676874677265656e3f7374796c653d666c61742d737175617265)](#)[![PRs Welcome](https://camo.githubusercontent.com/25b3e6d0d42c98de74a98cbb4d149a1c09020cf6d1361993b72d7d5b8ffed363/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5052732d77656c636f6d652d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](#contributing)

**Collect rows across multiple MySQL databases. Compute relationship matches. Emit the JSON [`dbrel-viz`](../dbrel-viz) consumes.**

[Quick Start](#-quick-start) • [Schema Format](#-schema-json-format) • [API](#-api-reference) • [Examples](#-examples) • [Companion Packages](#-companion-packages)

---

> **TL;DR** — Give it a JSON schema describing your tables and how they relate, pass it a database handle, and it produces a visualization-ready payload. No ORM, no AST parsing, no code generation.

Table of Contents
-----------------

[](#table-of-contents)

- [Why dbrel-data-php?](#-why-dbrel-data-php)
- [Features](#-features)
- [Installation](#-installation)
- [Quick Start](#-quick-start)
- [Schema JSON Format](#-schema-json-format)
- [API Reference](#-api-reference)
- [Relationship Types](#-relationship-types)
- [Integration Example](#-integration-example)
- [Adapting Your Database Layer](#-adapting-your-database-layer)
- [Architecture](#-architecture)
- [Companion Packages](#-companion-packages)
- [Requirements](#-requirements)
- [Contributing](#-contributing)
- [License](#-license)

---

Why dbrel-data-php?
-------------------

[](#why-dbrel-data-php)

Information-schema joins tell you about foreign keys. Your application knows about **everything else** — the `FIND_IN_SET` column that binds hosts to groups, the cross-database references between your primary DB and your helpdesk DB, the polymorphic `module_id` column that points at different tables depending on a `module_type` value.

`dbrel-data-php` lets you describe those relationships in one JSON file, then computes the *actual row matches* between them so your frontend can draw edges without ever looking at the raw data itself.

```
   ┌───────────────┐        ┌───────────────────┐        ┌──────────────┐
   │  JSON schema  │        │  Your MySQL DBs   │        │ dbrel-viz    │
   │               │   ┌───▶│                   │◀───┐   │  (browser)   │
   │ • modules     │   │    │  accounts         │    │   │              │
   │ • prefixes    │   │    │  vps              │    │   │  20 graph    │
   │ • primary keys│   │    │  domains ...      │    │   │  renderers   │
   │ • relationships    │                            │   │              │
   └───────────────┘   │                             │   └──────┬───────┘
                       │                             │          │
                       ▼                             ▼          │
                 ┌───────────────────────────────────────┐      │
                 │         dbrel-data-php                │──────┘
                 │                                       │  JSON
                 │  RelationshipSchema                   │
                 │  ├─ DataCollector (runs your SELECTs) │
                 │  ├─ RelationshipMatcher (O(N*M))      │
                 │  └─ DataProvider (emits payload)      │
                 └───────────────────────────────────────┘

```

Features
--------

[](#features)

- **JSON-defined schema** — one file describes your modules, prefixes, primary keys, and every kind of relationship
- **Three relationship types out of the box** — `direct` foreign-key matches, `find_in_set` CSV column bridges, `cross_db` cross-database refs
- **Works with *any* database layer** — implement a 5-method `DbInterface` around your existing `mysqli`/`PDO`/custom wrapper
- **Pivot filtering** — re-center the payload on a specific table/row and auto-trim to tables within 2 hops
- **Row-level match arrays** — not just "`accounts` links to `vps`", but exactly which rows link to which
- **Virtual tables** — synthesize tables from pivoted rows (e.g. `accounts_ext` built from a key/value `accounts_extra` table)
- **Metadata baked in** — query time, table / row counts, database list, pivot state
- **Zero framework lock-in** — vanilla PHP 7.4+ with PSR-4 autoloading, no Laravel/Symfony assumptions
- **Stable JSON output** — byte-compatible with the Node.js sister package [`dbrel-data-js`](../dbrel-data-js)

Installation
------------

[](#installation)

```
composer require detain/dbrel-data-php
```

Then require Composer's autoloader and use the classes:

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

use DbRel\Data\RelationshipSchema;
use DbRel\Data\DataCollector;
use DbRel\Data\DataProvider;
```

Quick Start
-----------

[](#quick-start)

A minimal endpoint that returns the payload for a given customer:

```
