PHP Classes

PHP MySQL Info to MD: Generate a MySQL table structure Markdown report

Recommend this page to a friend!
  Info   Example   Demos   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 66 All time: 10,365 This week: 455Up
Version License PHP version Categories
mysqlinfomd 1.0.0GNU General Publi...7.4Databases, Tools, PHP 7
Description 

Author

This package can generate a MySQL table structure Markdown report.

It takes a MySQLi database connection handler and performs queries to extract the structure of the database tables.

The package can generate reports in Markdown format to display the database table details like the table name, MySQL database engine, number of rows, last updated date, table fields, table keys and create table SQL statement.

Innovation Award
PHP Programming Innovation award nominee
April 2023
Number 11
MySQL is a prevalent SQL database server type many PHP developers use.

Sometimes developers want an overview of the MySQL database table structure details. There are several SQL commands that MySQL supports to give that overview.

This package provides an excellent presentation of the MySQL database table structure details in a way that is easier to understand than the output of the SQL query results that return that information.

Manuel Lemos
Picture of Stefan Kientzler
  Performance   Level  
Name: Stefan Kientzler is available for providing paid consulting. Contact Stefan Kientzler .
Classes: 19 packages by
Country: Germany Germany
Age: 57
All time rank: 71946 in Germany Germany
Week rank: 43 Up2 in Germany Germany Up
Innovation award
Innovation award
Nominee: 11x

Winner: 6x

Example

<?php
declare(strict_types=1);

use
SKien\MySqlTools\MySqlInfoMD;

/**
 * Generating report for MySQL Database in MD format.
 *
 * @author Stefanius <s.kientzler@online.de>
 * @copyright MIT License - see the LICENSE file for details
 */
include_once "autoloader.php";

$strDBHost = 'localhost';
$strDBName = 'demo';
$strDBUser = 'demo';
$strDBPwd = 'demoPWD';
$oDB = mysqli_connect($strDBHost, $strDBUser, $strDBPwd, $strDBName);

$iType = intval($_GET['type'] ?? '0');
$oInfo = new MySqlInfoMD($oDB, $iType);
switch (
$iType) {
    case
MySqlInfoMD::STANDALONE:
       
$oInfo->setOptions(MySqlInfoMD::OPT_CREATE_SUBFOLDER | MySqlInfoMD::OPT_CREATE_STMT);
       
$oInfo->setPath('/Example');
       
$oInfo->setImagePath('/images');
        echo
'Database information generated (Type: STANDALONE)';
        break;
    case
MySqlInfoMD::GITHUB_WIKI:
       
$oInfo->setOptions(MySqlInfoMD::OPT_CREATE_TOC | MySqlInfoMD::OPT_CREATE_STMT);
       
$oInfo->setPath('/GitHubWiki');
       
$oInfo->setImagePath('/images');
        echo
'Database information generated (Type: GITHUB_WIKI)';
        break;
    case
MySqlInfoMD::SKIEN_WIKI:
       
$oInfo->setOptions(MySqlInfoMD::OPT_CREATE_SUBFOLDER | MySqlInfoMD::OPT_CREATE_STMT | MySqlInfoMD::OPT_NO_INDEXLINK);
       
$oInfo->setRoot($_SERVER['DOCUMENT_ROOT']);
       
$oInfo->setPath('/packages/MySqlInfoMD/wiki/DBDesign');
       
$oInfo->setImagePath('/packages/MySqlInfoMD/wiki/images');
        echo
'Database information generated (Type: SKIEN_WIKI)';
        break;
}
$oInfo->buildInfo();


Details

Generating report for a given MySQL database as MD-Files

Latest Stable Version License Donate Minimum PHP Version

Overview

This class can generate a complete documentation of a MySQL database in Markdown format. In the MD format the documentation can be made available for everyone who is involved in an project containing a MySQL database. There are various scenarios: - The easies way is just make the files accessible at the filesystem/fileserver - More comfortable can be a webbased publication as part of an intra- or extranet since the MD format is wide supported - Or you can integrate it into other proprietaire layers (i.e. wikis, documentation systems, ...)

The report contains 1. An overview file with links to datail files for - tables - views - procedures - functions - trigger 2. Details for tables and views - all fields with datatype and keydefinition, nullable, defaultvalue - defined triggers - defined constraints

 - tables referenced by this table
 - tables that references this table
  1. Details for precedures, functions and trigger - create statement containing all infos

Usage

  1. Create an `mysqli` connection to the database to build the report for.
  2. Create an instance of the `MySqlInfoMD()` class and pass the DB connection
  3. Set prefered directories and options
  4. Call the `buildInfo()` method.
$strDBHost = 'localhost';
$strDBName = 'demo';
$strDBUser = 'demo';
$strDBPwd = 'demoPWD';
$oDB = mysqli_connect($strDBHost, $strDBUser, $strDBPwd, $strDBName);

$oInfo = new MySqlInfoMD($oDB, $MySqlInfoMD::STANDALONE);
$oInfo->setOptions(MySqlInfoMD::OPT_CREATE_SUBFOLDER | MySqlInfoMD::OPT_CREATE_STMT);
$oInfo->buildInfo();

> Note: > Since the Markdown renderer that is used at phpClasses.org do not support MD > tables, you will not get a satisfactory display if you look at the example directly > in the source view window here in the package.

Supported types

The report can be generated for - STANDALONE Create the MD files for standalone use (file or web based) to view with a browser addon or any MD viewer - GITHUB_WIKI Build the MD files to upload to a Github-Wiki. - SKIEN_WIKI Build the MD files for display inside a self defined structure for more complex wikis.

recommended browser add-ons

A very good display quality you get e.g. with the browser add-on *'Markdown Viewer'* (from somiv) that is available for most major browsers:

firefox

https://addons.mozilla.org/de/firefox/addon/markdown-viewer-chrome/

chrome

https://chrome.google.com/webstore/detail/markdown-viewer/ckkdlimhmcjmikdlpkmbgfkaikojcbjk?hl=de

or visit on github

https://github.com/simov/markdown-viewer


  Example ReportExternal page  

Open in a separate window

  Files folder image Files (15)  
File Role Description
Files folder imageExample (1 file, 2 directories)
Files folder imageSKien (1 directory)
Accessible without login Plain text file autoloader.php Aux. Auxiliary script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file MySqlInfoExample.php Example Example script
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file readme.md Doc. Documentation

  Files folder image Files (15)  /  Example  
File Role Description
Files folder imageimages (5 files)
Files folder imageTables (3 files)
  Accessible without login Plain text file index.md Data Auxiliary data

  Files folder image Files (15)  /  Example  /  images  
File Role Description
  Accessible without login Image file checked.png Icon Icon image
  Accessible without login Image file mul_key.png Icon Icon image
  Accessible without login Image file pri_key.png Icon Icon image
  Accessible without login Image file unchecked.png Icon Icon image
  Accessible without login Image file uni_key.png Icon Icon image

  Files folder image Files (15)  /  Example  /  Tables  
File Role Description
  Accessible without login Plain text file Table_Board.md Data Auxiliary data
  Accessible without login Plain text file Table_Employee.md Data Auxiliary data
  Accessible without login Plain text file Table_Section.md Data Auxiliary data

  Files folder image Files (15)  /  SKien  
File Role Description
Files folder imageMySqlTools (1 file)

  Files folder image Files (15)  /  SKien  /  MySqlTools  
File Role Description
  Plain text file MySqlInfoMD.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:66
This week:0
All time:10,365
This week:455Up