Download the PHP package detain/dbrel-data-php without Composer

On this page you can find all versions of the php package detain/dbrel-data-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package dbrel-data-php

# dbrel-data-php ### PHP backend that turns your MySQL schema into an interactive relationship graph. [![Latest Version on Packagist](https://img.shields.io/packagist/v/detain/dbrel-data-php.svg?style=flat-square&color=brightgreen)](https://packagist.org/packages/detain/dbrel-data-php) [![Total Downloads](https://img.shields.io/packagist/dt/detain/dbrel-data-php.svg?style=flat-square)](https://packagist.org/packages/detain/dbrel-data-php) [![PHP Version](https://img.shields.io/packagist/php-v/detain/dbrel-data-php?style=flat-square)](https://www.php.net/) [![License](https://img.shields.io/packagist/l/detain/dbrel-data-php.svg?style=flat-square&color=blue)](./LICENSE) [![Build Status](https://img.shields.io/badge/build-passing-success?style=flat-square)](#) [![Code Coverage](https://img.shields.io/badge/coverage-95%25-brightgreen?style=flat-square)](#) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](#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


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.

Features

Installation

Then require Composer's autoloader and use the classes:

Quick Start

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

Hand that JSON to dbrel-viz and you're done.

Schema JSON Format

The schema is a single JSON file with these top-level keys. The library only strictly requires relationships; everything else is for metadata and display.

Relationship-object fields (click to expand) | Field | Type | Required | Description | | :-- | :-- | :-: | :-- | | `source_db` | `string` | yes | Logical database name, e.g. `"my"` | | `source_table` | `string` | yes | Source table name | | `source_field` | `string` | yes | Column on the source holding the reference | | `target_db` | `string` | yes | Logical database name of the target | | `target_table` | `string` | yes | Target table name | | `target_field` | `string` | yes | Column on the target being referenced | | `type` | `string` | no | `direct` \| `find_in_set` \| `cross_db` (default `direct`) | | `cardinality` | `string` | no | `1:1` \| `1:N` \| `N:1` \| `N:M` (default `1:N`) | | `label` | `string` | no | Human-readable label for tooltips | | `notes` | `string` | no | Free-text notes — stored but unused by the matcher | Unknown types (e.g. `code_join`, `fk_constraint`) are normalized to `direct`. Relationships whose `target_table` starts with `(` (polymorphic placeholders like `(vps|websites)`) are silently skipped.

API Reference

DbRel\Data\RelationshipSchema

Loads and normalizes the relationship schema JSON.

Method Returns Description
__construct(string\|array $jsonPathOrArray) Accepts a file path or a pre-decoded array. Throws InvalidArgumentException on bad input.
getRules(): array array Normalized relationship rules (ready for the matcher).
getModules(): array array Module definitions keyed by module name.
getTableToModule(): array array Lookup map: table name → module name.
getVirtualTables(): array array Virtual table definitions (e.g. pivot-synthesized tables).
getMetadata(): array array The _metadata block from the JSON.
getRaw(): array array The raw decoded JSON.

DbRel\Data\DataCollector

Accumulates rows from SQL queries into a normalized structure.

Method Description
collect(DbInterface $db, string $dbName, string $table, string $sql, int $limit = 50): void Runs $sql and captures up to $limit rows. Records full $total.
addTable(string $dbName, string $table, array $rows, array $columns, ?int $total = null): void Manually register a table (for virtual tables, caches, etc).
appendRows(string $dbName, string $table, array $rows): void Append rows to an existing table or create it.
getTables(): array Every collected table, keyed by "db.table".
has(string $key): bool Whether a given "db.table" key exists.
getRows(string $key): array Rows for a given key (empty if missing).
getTotalRows(): int Sum of total across all tables.

DbRel\Data\RelationshipMatcher

Given collected data and schema rules, computes row-level match arrays.

Method Description
compute(array $tablesData, array $rules): array Returns the active relationships, each with a matches array of [sourceRowIdx, [targetRowIdxs]].

Algorithmic behavior:

DbRel\Data\DataProvider

Ties everything together and emits the final payload.

Method Description
__construct(RelationshipSchema $schema, ?RelationshipMatcher $matcher = null) Instantiate. Records a start time for query_time_ms.
build(DataCollector $collector, array $options = []): array Produces the payload.
getSchema(): RelationshipSchema Accessor.
getMatcher(): RelationshipMatcher Accessor.
build() options (click to expand) | Key | Type | Default | Description | | :-- | :-- | :-: | :-- | | `custid` | `int` | `0` | Customer/entity ID — echoed into metadata | | `primaryKeys` | `array` | `[]` | Map of table → PK column name (used by the frontend for node labels) | | `prefixes` | `array` | `[]` | Map of table → prefix that the frontend strips for display (e.g. `vps_hostname` → `hostname`) | | `hiddenFields` | `string[]` | `[]` | Columns the frontend must never render | | `pivotTable` | `string` | `''` | If set, only keeps tables within 2 hops of `my.{pivotTable}` | | `pivotId` | `int` | `0` | Echoed into metadata for the frontend's breadcrumb |
Response shape (click to expand)

DbRel\Data\DbInterface

A 5-method contract your database wrapper must satisfy.

If you use MyAdmin's \MyDb\Mysqli\Db, it already matches — no adapter needed. For other stacks see Adapting Your Database Layer.

Relationship Types

The schema supports several type values. Internally the matcher collapses them down to three behaviors.

| Schema type | Computed as | Behavior | | :-- | :-: | :-- | | `direct` | `direct` | Exact string match between `source_field` and `target_field` | | `fk_constraint` | `direct` | Same as `direct` — source was an explicit FK in `information_schema` | | `implicit_fk` | `direct` | Same as `direct` — discovered from code rather than DB constraints | | `code_join` | `direct` | Same as `direct` — found in a `JOIN` in application code | | `find_in_set` | `find_in_set` | Source field is a CSV; split on `,` and match each piece | | `cross_db` | `cross_db` | Exact match, but the source and target live in different logical DBs | | `polymorphic` | — | Skipped (the `target_table` is parenthesized, e.g. `(vps|websites)`) | | `conditional` | `direct` | Treated as direct; add a `notes` field for humans |

direct

Classic FK join. Cheap, O(N×M) with early-exit on null/zero/empty source values.

find_in_set

Source column is CSV. The matcher splits it on ,, trims each token, and checks each target row's value against the set.

cross_db

Same matching logic as direct, but the frontend draws the edge in a different style so you can see DB boundaries at a glance.

Integration Example

Drop-in AJAX endpoint using a procedural entry point:

Point dbrel-viz's ajaxUrl at this script and you have a working, swappable-renderer database explorer.

Adapting Your Database Layer

You only need to implement the 5-method DbInterface. Example wrapping PDO:

Collectors expect DbInterface::next_record() to leave the current row on a $db->Record public property — this matches the MyAdmin and PHPLIB tradition. If your wrapper returns rows differently, either set $this->Record in next_record() (as above) or expose getRecord(): array which DataCollector will call via method_exists().

Architecture

Companion Packages

This package is half of a two-package system:

Package Language Purpose
@detain/dbrel-viz Browser JS Frontend library — 20 pluggable renderers
detain/dbrel-data-php PHP ≥ 7.4 This package — the backend
@detain/dbrel-data-js Node ≥ 14 Same API, for Node/Express stacks

Payload paritydbrel-data-php and dbrel-data-js emit byte-identical JSON given the same schema and data. Swap backends freely; the frontend won't notice.

Requirements

Contributing

PR guidelines

  1. One feature or fix per PR
  2. New relationship types go on RelationshipMatcher; schema format is frozen
  3. All public APIs must carry PHPDoc
  4. PHPUnit tests for any behavior change
  5. PSR-12 code style

Ideas we'd love help with

License

Joe Huss / InterServer


**[⬆ back to top](#dbrel-data-php)** Made with care by [InterServer](https://www.interserver.net). Pair with [dbrel-viz](../dbrel-viz) and [dbrel-data-js](../dbrel-data-js).

All versions of dbrel-data-php with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-json Version *
ext-mysqli Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package detain/dbrel-data-php contains the following files

Loading the files please wait ...