<?php

echo "digraph structs {\n";
echo "    node [shape=record];\n";
echo "\n";

$schema = "<your-schema-name>";
$pdo = new PDO('mysql:host=xps1;charset=utf8mb4;dbname=mysql', 'user', '********');

$sql = "select table_name from information_schema.tables WHERE table_schema = :schema order by table_name";
$stmt = $pdo->prepare($sql);
$stmt->execute(['schema' => $schema]);
$tables = $stmt->fetchAll(PDO::FETCH_OBJ);

$sql = "select column_name, column_default, is_nullable, data_type from information_schema.columns where table_schema = :schema and table_name = :table order by ordinal_position";
$stmt = $pdo->prepare($sql);

foreach ($tables as $table) {
    $table_name = $table->table_name;

    echo "    $table_name [shape=none, label=<\n";
    echo "        <table border=\"0\" cellspacing=\"0\" cellborder=\"1\">\n";
    echo "            <tr><td align=\"left\" bgcolor=\"lightblue2\">$table_name</td></tr>\n";

    $stmt->execute(['schema' => $schema, 'table' => $table_name]);
    $columns = $stmt->fetchAll(PDO::FETCH_OBJ);

    foreach ($columns as $column) {
        $column_name = $column->column_name;
        $data_type = $column->data_type;

        echo "            <tr><td port=\"$column_name\" align=\"left\">$column_name ($data_type)</td></tr>\n";
    }

    echo "        </table>\n";
    echo "    >];\n";
    echo "\n";
}

echo "}\n";
Close Copy