濮阳杆衣贸易有限公司

主頁 > 知識(shí)庫 > PHP實(shí)現(xiàn)生成數(shù)據(jù)字典功能示例

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

熱門標(biāo)簽:遼寧ai電銷機(jī)器人價(jià)格 福建銀行智能外呼系統(tǒng)價(jià)格 寧波外呼營銷系統(tǒng) 房產(chǎn)中介用的是什么外呼系統(tǒng) 長沙做地圖標(biāo)注公司 四川保險(xiǎn)智能外呼系統(tǒng)供應(yīng)商 電話機(jī)器人銷售主要負(fù)責(zé)什么 地圖標(biāo)注專員怎么樣 上海做外呼線路的通信公司

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

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

效果展示:

說了這么多廢話了,終于開始寫代碼了:

?php
/**
* 生成mysql數(shù)據(jù)字典
*/
//配置數(shù)據(jù)庫
$dbserver  = "127.0.0.1";
$dbusername = "賬號(hào)";
$dbpassword = "密碼";
$database   = "數(shù)據(jù)庫";
//其他配置
$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ù)類型/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)容感興趣的讀者可查看本站專題:《php+mysql數(shù)據(jù)庫操作入門教程》、《php+mysqli數(shù)據(jù)庫程序設(shè)計(jì)技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總》

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

您可能感興趣的文章:
  • php生成mysql的數(shù)據(jù)字典
  • PHP實(shí)現(xiàn)獲取并生成數(shù)據(jù)庫字典的方法
  • ThinkPHP框架實(shí)現(xiàn)的MySQL數(shù)據(jù)庫備份功能示例
  • PHP備份/還原MySQL數(shù)據(jù)庫的代碼
  • php實(shí)現(xiàn)mysql數(shù)據(jù)庫備份類
  • 使用PHP備份MYSQL數(shù)據(jù)的多種方法
  • php MYSQL 數(shù)據(jù)備份類
  • php實(shí)現(xiàn)MySQL數(shù)據(jù)庫備份與還原類實(shí)例
  • 使用php自動(dòng)備份數(shù)據(jù)庫表的實(shí)現(xiàn)方法
  • 用PHP實(shí)現(xiàn)XML備份Mysql數(shù)據(jù)庫

標(biāo)簽:常德 佛山 深圳 澳門 延安 工商登記 宿遷 宜春

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PHP實(shí)現(xiàn)生成數(shù)據(jù)字典功能示例》,本文關(guān)鍵詞  PHP,實(shí)現(xiàn),生成,數(shù)據(jù),字典,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《PHP實(shí)現(xiàn)生成數(shù)據(jù)字典功能示例》相關(guān)的同類信息!
  • 本頁收集關(guān)于PHP實(shí)現(xiàn)生成數(shù)據(jù)字典功能示例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    铜梁县| 上犹县| 平利县| 青岛市| 章丘市| 洛浦县| 阿合奇县| 于都县| 亚东县| 株洲市| 调兵山市| 赞皇县| 赣榆县| 通城县| 富顺县| 中卫市| 辉县市| 麻城市| 宜昌市| 朔州市| 板桥市| 贵溪市| 静安区| 舞钢市| 高淳县| 高青县| 抚远县| 浮山县| 田林县| 原平市| 汽车| 安庆市| 永安市| 威信县| 北京市| 西藏| 昌黎县| 利川市| 洛浦县| 蚌埠市| 郸城县|