PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Sylvia Sotomayor  >  Data Dictionary  >  index.php  >  Download  
File: index.php
Role: Example script
Content type: text/plain
Description: main example page
Class: Data Dictionary
Output the structure of a MySQL database
Author: By
Last change:
Date: 10 years ago
Size: 2,980 bytes


Class file image Download

//which database to use
if (isset($_GET['db'])) {
$dbase = $_GET['db'];
} else if (isset(
$_SESSION['dbase'])) {
$dbase = $_SESSION['dbase'];
} else {
$_SESSION['dbase'] = $dbase;

//make sure you have the correct pdo driver activated
$dsn="mysql"; //for MySQL
#$dsn="mssql"; //for MS SQL
#$dsn="sqlite"; //for SQLite
#$dsn="pgsql"; //for PostgreSQL

//do not use this on a publicly accessible server
//do not use this on a production server
//for development use only
//use at your own risk

//change this to what is needed to access the server

#end Parameters

if (isset($_GET['type'])) {
$type = $_GET['type'];
$ddc = new DDConverter($type, $dsn, $host, $dbase, $user, $pass);

$dd = new DataDictionary($dsn, $host, $dbase, $user, $pass);
$ddp = new DDPresenter();
print('<?xml version="1.0" encoding="utf-8"?>'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" xml:lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="Sylvia Sotomayor" />
<title>Database Information</title>
<link rel="stylesheet" type="text/css" href="schemas.css" />
<!-- navbar: list of available databases -->
<div class="navbar">
//create navigation bar with database names
$dbarray = $dd->getDBarray();
$navbar = $ddp->createDBNavbar($dbarray);
<div id="main">
<h1>Database: <?php echo $dbase; ?></h1>
<!-- list of tables in database -->
//create list of tables in database
$dbtablearray = $dd->getDBtablearray();
$headers = $dd->getColumnHeadings($dbtablearray[0]);
$dbtables = $ddp->createTable($dbtablearray, $headers);

//get list of table names
$tablearray = $dd->getTablearray();
$tablebar = $ddp->createTablesNavbar($tablearray);
<!-- navbar: list of database tables -->
<div class="navbar">
<?php echo $tablebar; ?>
<!-- list of columns in each table -->
foreach ($tablearray as $table) {
"<h2><a name=\"$table\">Table: $table</a></h2>");
$colarray = $dd->getColarray($table);
$headers = $dd->getColumnHeadings($colarray[0]);
$tabledetails = $ddp->createTable($colarray, $headers);
<!-- repeat navbar: list of available databases -->
<div class="navbar">
<p>Convert Data Dictionary to: <a href="<?php echo $_SERVER['PHP_SELF']; ?>?type=csv">CSV</a> <a href="<?php echo $_SERVER['PHP_SELF']; ?>?type=xml">XML</a></p>

For more information send a message to info at phpclasses dot org.