1. 程式人生 > >挨踢小子MySQL資料字典原始碼

挨踢小子MySQL資料字典原始碼

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>挨踢小子資料字典詳細說明</title>
<style>
*{margin:0px;padding:0px;font-size:14px;}
.boxtab{width:1100px;margin:0px auto;}
.tab{border: 1px solid #C1DAD7;    border-collapse: collapse;}
.tab{width:100%;}
h3{line-height:50px;text-align:center;font-size:30px;}
h2{line-height:50px;text-align:center;font-size:20px;}
.tab th{background: #d6eef0; padding: 5px;}
.tab tr td{border: 1px solid #C1DAD7;border-collapse: collapse;	line-height:30px;}
.zilist{position: fixed;left: 10px;background: #fff;border: 1px solid #c8c8c8;padding: 8px;    width: 202px;}
.zilist a{display:block;line-height:35px;font-size:14px;color:#333;text-decoration: none;float: left;width: 100px;height:35px;overflow:hidden;text-align: center;border-bottom: 1px solid #c8c8c8;}
.zilist a:hover{background:#f8f8f8;}
.zilist a:nth-child(odd){border-right: 1px solid #c8c8c8;}
td {padding: 3px 5px 3px 10px;vertical-align: top;}
.tab tr:nth-child(odd){background:#f8f8f8;}
.tab tr:hover{background:#E8E8E8;}
.cor{line-height:30px;text-align:center;color: #535886;background: rgba(220,229,239,0.9);}
</style>
</head>
<body class="boxtab">
<div class="menu">
   <h3>挨踢小子資料字典詳細說明</h3>
</div>
<?php 	
/**
 * @project: 挨踢小子資料字典詳細說明
 * @desc: 該檔案應該放置於php執行環境之下,並配置下面的資料庫。在建表過程中需要注意資料表註釋,資料欄位註釋
 * @author: Aiti
 * @email: 
[email protected]
* @time: 2018年10月15日上午9:31:12 */ date_default_timezone_set("PRC"); $mysql_conf = array( 'host' => '127.0.0.1', //資料庫的連結IP地址 'db' => 'information_schema', //資料庫名稱 'db_user' => 'root', //登入使用者名稱 'db_pwd' => 'root', //登入密碼 ); $mysqli = @new mysqli($mysql_conf['host'], $mysql_conf['db_user'], $mysql_conf['db_pwd']); if ($mysqli->connect_errno) { die("could not connect to the database:\n" . $mysqli->connect_error);//診斷連線錯誤 } $mysqli->query("set names 'utf8';");//編碼轉化 $select_db = $mysqli->select_db($mysql_conf['db']); if (!$select_db) { die("could not connect to the db:\n" . $mysqli->error); } //獲取該資料庫下面所有的表和表註釋 $tablesql="Select table_name table_name,TABLE_COMMENT table_annotation from INFORMATION_SCHEMA.TABLES Where table_schema = '".$mysql_conf['db']."'"; $tableresone = $mysqli->query($tablesql); $tablerestwo = $mysqli->query($tablesql); echo "<ul class='zilist'>"; $newstr=''; while ($tablerow =$tableresone->fetch_assoc()) { if(empty($tablerow['table_annotation'])){ $newstr.="<a href='#tab".$tablerow['table_name']."'>".$tablerow['table_name']."</a>"; }else{ $newstr.="<a href='#tab".$tablerow['table_name']."'>".$tablerow['table_annotation']."</a>"; } } echo $newstr."</ul>"; while ($tablerow =$tablerestwo->fetch_assoc()) { // 遍歷資料庫中的表名組裝語句 $infosql = "SELECT `COLUMN_NAME`, `COLUMN_TYPE`, `DATA_TYPE`, `CHARACTER_MAXIMUM_LENGTH`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `COLUMN_COMMENT` FROM INFORMATION_SCHEMA.COLUMNS where table_schema ='".$mysql_conf['db']."' AND table_name ='{$tablerow['table_name']}'"; $infores = $mysqli->query($infosql); if (!$infores) { die("sql error:\n" . $mysqli->error); } echo '<h2 id="tab'.$tablerow['table_name'].'">'.$tablerow['table_name']." ".$tablerow['table_annotation']."</h2>"; echo "<table class='tab'>"; echo "</caption> <tr> <th>欄位名</th> <th>資料型別</th> <th>欄位型別</th> <th>長度</th> <th>是否為空</th> <th>預設值</th> <th>備註</th> </tr>"; while ($inforow = $infores->fetch_assoc()) { // 遍歷輸出表中的各項欄位的資訊 echo "<tr> <td>".$inforow['COLUMN_NAME']."</td> <td>".$inforow['COLUMN_TYPE']."</td> <td>".$inforow['DATA_TYPE']."</td> <td>".$inforow['CHARACTER_MAXIMUM_LENGTH']."</td> <td>".$inforow['IS_NULLABLE']."</td> <td>".$inforow['COLUMN_DEFAULT']."</td> <td>" .$inforow['COLUMN_COMMENT']."</td> </tr>"; } echo "</table>"; echo "<br>"; $infores->free(); } $tableresone->free(); $tablerestwo->free(); $mysqli->close(); ?> <div class="cor">版權所有2018-2019 Create By Aiti</div> </body> </html>