PHP下phpMyAdmin数据字典美化代码
一、将下面的文件存储到phpMyAdmin根目录下
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Renders data dictionary
*
* @package PhpMyAdmin
*/
/**
* Gets the variables sent or posted to this script, then displays headers
*/
require_once 'libraries/common.inc.php';
$response = PMA\libraries\Response::getInstance();
$header = $response->getHeader();
$header->enablePrintView();
$html = '';
$GLOBALS['dbi']->selectDb($db);
$tables = $GLOBALS['dbi']->getTables($db);
//循环取得所有表的备注及表中列消息
foreach ($tables as $table){
$comments = PMA_getComments($db, $table);
$table_comment = $GLOBALS['dbi']->getTable($db, $table)
->getStatusInfo('TABLE_COMMENT');
//$html .= '<p><h2>'. $v['TABLE_COMMENT'] . ' </h2>';
$html.=' <div class="caption">'.$table.' '.$table_comment.'</div>'.PHP_EOL;
$html.=' <table border="1" cellspacing="0" cellpadding="0" align="center">'.PHP_EOL;
$html.=' <tbody>
<tr>
<th>字段名</th>
<th>数据类型</th>
<th>默认值</th>
<th>允许非空</th>
<th>自动递增</th>
<th>备注</th>
</tr>'.PHP_EOL;
$html.='';
$columns = $GLOBALS['dbi']->getColumns($db, $table);
foreach ($columns as $column){
$html.=' <tr>
<td>'.$column['Field'].'</td>'.PHP_EOL;
$html.=' <td>'.$column['Type'].'</td>'.PHP_EOL;
$html.=' <td> '.$column['Default'].'</td>'.PHP_EOL;
$html.=' <td> '.$column['Null'].'</td>'.PHP_EOL;
$html.=' <td>'.($column['Extra']=='auto_increment'?'自增':
' ').' '.($column['Key']=='PRI'?'主键':
' ').'</td>'.PHP_EOL;
$html.=' <td> '.(isset($comments[$column['Field']]) ? htmlspecialchars($comments[$column['Field']]) : "").'</td>'.PHP_EOL;
$html.=' </tr>'.PHP_EOL;
}
$html.=' </tbody>
</table>'.PHP_EOL;
}
?>
<style>
html,body{
padding:0px;
}
body,td,th{
font-family:"Helvetica Neue, Helvetica, PingFang SC, Tahoma, Arial, sans-serif";
}
table{
border-collapse:collapse;
border:1px solid #CCC;
background:#efefef;
width:100%;
}
.caption{
text-align:left;
background-color:#fff;
font-size:18px;
font-weight:bold;
padding-top:20px;
padding-bottom: 10px;
}
table th{
text-align:left;
font-weight:bold;
height:26px;
line-height:26px;
font-size:14px;
border:1px solid #CCC;
padding:5px 10px;
width:15%;
}
table td{
height:20px;
font-size:14px;
border:1px solid #CCC;
background-color:#fff;
color:#333;
padding:5px 10px;
}
</style>
<h1>数据字典</h1>
<?php echo $html;?>
二、修改db_datadict.php文件
头部加入这几行
unset($_GET['goto']);
$url = "hamm.php?".http_build_query($_GET);
header('Location: '.$url);die;
上边的hamm.php就是刚才创建的文件。