PHP Classes
elePHPant
Icontem

File: index.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  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: 3 years ago
Size: 2,980 bytes
 

Contents

Class file image Download
<?php
session_start
();
require_once(
'DataDictionary.class.php');
include_once(
'DDPresenter.class.php');
include_once(
'DDConverter.class.php');

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

#Parameters
//make sure you have the correct pdo driver activated
//http://www.php.net/manual/en/pdo.drivers.php
$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
$host="localhost";
//$host="127.0.0.1;port=3307";

//change this to what is needed to access the server
$user="myusername";
$pass="mypassword";

#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();
?>
<?php
print('<?xml version="1.0" encoding="utf-8"?>'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<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" />
</head>
<body>
<!-- navbar: list of available databases -->
<div class="navbar">
<?php
//create navigation bar with database names
$dbarray = $dd->getDBarray();
$navbar = $ddp->createDBNavbar($dbarray);
echo
$navbar;
?>
</div>
<div id="main">
<h1>Database: <?php echo $dbase; ?></h1>
<!-- list of tables in database -->
<?php
//create list of tables in database
$dbtablearray = $dd->getDBtablearray();
$headers = $dd->getColumnHeadings($dbtablearray[0]);
$dbtables = $ddp->createTable($dbtablearray, $headers);
echo
$dbtables;

//get list of table names
$tablearray = $dd->getTablearray();
$tablebar = $ddp->createTablesNavbar($tablearray);
?>
<!-- navbar: list of database tables -->
<div class="navbar">
<?php echo $tablebar; ?>
</div>
<!-- list of columns in each table -->
<?php
foreach ($tablearray as $table) {
    print(
"<h2><a name=\"$table\">Table: $table</a></h2>");
   
$colarray = $dd->getColarray($table);
   
$headers = $dd->getColumnHeadings($colarray[0]);
   
$tabledetails = $ddp->createTable($colarray, $headers);
    echo
$tabledetails;
}
?>
</div>
<!-- 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>
</div>
</body>
</html>