Database specification describes the physical data structure on a system or application. Specifications database presents how the storage of data performed by the database software. In the system documentation, including the CTF report and dissertation, the specification data base also needs to be displayed. The form of the specification of the database itself is generally in the form of tables that provide information fields for all tables that are used. Information fields shown include field names, field types, length fields and fields that became the key field (primary key).
Simply, to create a database specification, we can use Microsoft Word or Open Office Writer. Information tables and fields derived from analysis of systems in the form class diagram or ERD (Entity Relationship Diagram). Well from the specification database, then created the structure of tables in a DBMS such as MySQL or Oracle. After the tables in the DBMS is ready, then the program (application) is built.

To generate database table specification, the following program uses some built-in functions related PHP with MySQL, namely:
- mysql_connect () toa connection to the MySQL database .
- mysql_select_db () to open the database to be used.
- mysql_query () to execute (run) command queries to MySQL from PHP.
- mysql_fetch_row () to take the value of the query results generated by the function mysql_query (). Query results are included in the PHP array.
- mysql_num_fields () to produce a number of fields from a table.
- mysql_fetch_field () to get information (metadata) from a field in the table.
- mysql_field_len () to get the length information (length) of each field in the table.
<html>Information :
<head><title>MySQL Database Spesification Creator</title>
<style type="text/css">
table.db-table { border-right:1px solid #ccc; border-bottom:1px solid #ccc; }
table.db-table th{ background:#eee; padding:5px; border-left:1px solid #ccc;
border-top:1px solid #ccc; }
table.db-table td{ padding:5px; border-left:1px solid #ccc;
border-top:1px solid #ccc; }
</style>
</head>
<body>
<?php
/* connect to the db */
$connection = mysql_connect('localhost','user','password');
mysql_select_db('nama_database',$connection);
/* show tables */
$result = mysql_query('SHOW TABLES',$connection) or die('cannot show tables');
while($tableName = mysql_fetch_row($result)) {
$table = $tableName[0];
echo '<h3>',$table,'</h3>';
$result2 = mysql_query('SELECT * FROM '.$table.' LIMIT 1')
or die('cannot select from '.$table);
$i = 0;
echo '<table cellpadding="0" cellspacing="0" class="db-table">';
echo '<tr><th>No</th><th>Nama Field</th><th>Type</th><th>Panjang
</th><th>Keterangan</th></tr>';
while($i< mysql_num_fields($result2)) {
$meta = mysql_fetch_field($result2, $i);
$length = mysql_field_len($result2, $i);
echo '<tr>';
echo '<td>'.($i+1).'</td>'; //nomor
echo '<td>'.(($meta->primary_key)?'<u>'.$meta->name.'</u>' :
$meta->name).'</td>'; //nama field
echo '<td>'.$meta->type.'</td>'; //tipe field
echo '<td>'.$length.'</td>'; //panjang
echo '<td>'.$meta->name.'</td>'; //keterangan
echo '</tr>';
$i++;
}
echo '</table><br />';
}
?>
</body>
</html>
You can change the table in the program are:
Panjang : Long or length
Keterangan : Information
Panjang : Long or length
Keterangan : Information
0 comments on PHP Program for Displaying Database Specifications :
Post a Comment and Don't Spam!
Dont Spam please