欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP實(shí)現(xiàn)生成數(shù)據(jù)字典功能示例

 更新時(shí)間:2018年05月24日 14:35:15   作者:請(qǐng)叫我郝先生  
這篇文章主要介紹了PHP實(shí)現(xiàn)生成數(shù)據(jù)字典功能,涉及php針對(duì)mysql常見(jiàn)的連接、數(shù)據(jù)表查詢(xún)、遍歷、table表格構(gòu)成等相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了PHP實(shí)現(xiàn)生成數(shù)據(jù)字典功能。分享給大家供大家參考,具體如下:

最近時(shí)間緊迫,沒(méi)有時(shí)間發(fā)博客,趁現(xiàn)在有點(diǎn)時(shí)間向大家分享一個(gè)知識(shí)點(diǎn)。在咱們做開(kāi)發(fā)的時(shí)候 ,也許經(jīng)常會(huì)遇到對(duì)數(shù)據(jù)庫(kù)分析,做一個(gè)數(shù)據(jù)字典,那么現(xiàn)在好處來(lái)了,大家只需要關(guān)注我所發(fā)送的這個(gè)鏈接輕輕松松幫你們搞定數(shù)據(jù)字典的設(shè)計(jì),再也不用你們下載數(shù)據(jù)字典那個(gè)工具,作為一個(gè)開(kāi)發(fā)人員,隨便幾行代碼就應(yīng)該會(huì)搞定這個(gè)知識(shí),那么現(xiàn)在廢話我也不多說(shuō)了,大家看底下的代碼,大家只需要改一下你的數(shù)據(jù)庫(kù)賬號(hào)和密碼然后運(yùn)行一下就可以了。

效果展示:

說(shuō)了這么多廢話了,終于開(kāi)始寫(xiě)代碼了:

<?php
/**
* 生成mysql數(shù)據(jù)字典
*/
//配置數(shù)據(jù)庫(kù)
$dbserver  = "127.0.0.1";
$dbusername = "賬號(hào)";
$dbpassword = "密碼";
$database   = "數(shù)據(jù)庫(kù)";
//其他配置
$title = '數(shù)據(jù)字典';
$mysql_conn = @mysql_connect("$dbserver", "$dbusername", "$dbpassword") or die("Mysql connect is error.");
mysql_select_db($database, $mysql_conn);
mysql_query('SET NAMES utf8', $mysql_conn);
$table_result = mysql_query('show tables', $mysql_conn);
//取得所有的表名
while ($row = mysql_fetch_array($table_result)) {
   $tables[]['TABLE_NAME'] = $row[0];
}
//循環(huán)取得所有表的備注及表中列消息
foreach ($tables AS $k=>$v) {
   $sql = 'SELECT * FROM ';
   $sql .= 'INFORMATION_SCHEMA.TABLES ';
   $sql .= 'WHERE ';
   $sql .= "table_name = '{$v['TABLE_NAME']}' AND table_schema = '{$database}'";
   $table_result = mysql_query($sql, $mysql_conn);
   while ($t = mysql_fetch_array($table_result) ) {
     $tables[$k]['TABLE_COMMENT'] = $t['TABLE_COMMENT'];
   }
   $sql = 'SELECT * FROM ';
   $sql .= 'INFORMATION_SCHEMA.COLUMNS ';
   $sql .= 'WHERE ';
   $sql .= "table_name = '{$v['TABLE_NAME']}' AND table_schema = '{$database}'";
   $fields = array();
   $field_result = mysql_query($sql, $mysql_conn);
   while ($t = mysql_fetch_array($field_result) ) {
     $fields[] = $t;
   }
   $tables[$k]['COLUMN'] = $fields;
}
mysql_close($mysql_conn);
$html = '';
//循環(huán)所有表
foreach ($tables AS $k=>$v) {
   //$html .= '<p><h2>'. $v['TABLE_COMMENT'] . ' </h2>';
   $html .= '<table border="1" cellspacing="0" cellpadding="0" align="center">';
   $html .= '<caption>' . $v['TABLE_NAME'] .' '. $v['TABLE_COMMENT']. '</caption>';
   $html .= '<tbody><tr><th>字段名</th><th>數(shù)據(jù)類(lèi)型</th><th>默認(rèn)值</th>
   <th>允許非空</th>
   <th>自動(dòng)遞增</th><th>備注</th></tr>';
   $html .= '';
   foreach ($v['COLUMN'] AS $f) {
     $html .= '<tr><td class="c1">' . $f['COLUMN_NAME'] . '</td>';
     $html .= '<td class="c2">' . $f['COLUMN_TYPE'] . '</td>';
     $html .= '<td class="c3"> ' . $f['COLUMN_DEFAULT'] . '</td>';
     $html .= '<td class="c4"> ' . $f['IS_NULLABLE'] . '</td>';
     $html .= '<td class="c5">' . ($f['EXTRA']=='auto_increment'?'是':' ') . '</td>';
     $html .= '<td class="c6"> ' . $f['COLUMN_COMMENT'] . '</td>';
     $html .= '</tr>';
   }
   $html .= '</tbody></table></p>';
}
//輸出
echo '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>'.$title.'</title>
<style>
body,td,th {font-family:"宋體"; font-size:12px;}
table{border-collapse:collapse;border:1px solid #CCC;background:#efefef;}
table caption{text-align:left; background-color:#fff; line-height:2em; font-size:14px; font-weight:bold; }
table th{text-align:left; font-weight:bold;height:26px; line-height:26px; font-size:12px; border:1px solid #CCC;}
table td{height:20px; font-size:12px; border:1px solid #CCC;background-color:#fff;}
.c1{ width: 120px;}
.c2{ width: 120px;}
.c3{ width: 70px;}
.c4{ width: 80px;}
.c5{ width: 80px;}
.c6{ width: 270px;}
</style>
</head>
<body>';
echo '<h1 style="text-align:center;">'.$title.'</h1>';
echo $html;
echo '</body></html>';
?>

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》、《php+mysqli數(shù)據(jù)庫(kù)程序設(shè)計(jì)技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論