挨踢小子MySQL数据字典源码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37126357/article/details/83378305
<!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>


猜你喜欢

转载自blog.csdn.net/qq_37126357/article/details/83378305