日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長提供免費(fèi)收錄網(wǎng)站服務(wù),提交前請(qǐng)做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點(diǎn)擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會(huì)員:747

這篇教程教大家做一個(gè)自動(dòng)生成數(shù)據(jù)庫數(shù)據(jù)字典HTML文件的代碼,有時(shí)候在開發(fā)系統(tǒng)制作系統(tǒng)說明的時(shí)候很有用。不多說了,直接上代碼:

mysql字典生成代碼

<?php
// -h host  -u user  -p password -P port -c charset -d dbname 
$param = getopt('h:u:p:P:c:d:');
$host = $param['h'] ?? '127.0.0.1';
$port = $param['P'] ?? 3306;
$user = $param['u'] ?? 'root';
$pass = $param['p'] ?? '123456';
$charset = $param['c'] ?? 'utf8';
$dbname = $param['d'] ?? '';
$dsn = "mysql:dbname={$dbname};host={$host};port={$port}";
try {
    $pdo = new PDO($dsn, $user, $pass, [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"]);
} catch (PDOException $e) {
    echo 'Connection failed:' . $e->getMessage();
}
//獲取數(shù)據(jù)庫中所有表信息
$sql = "SHOW TABLE STATUS FROM {$dbname}";
$result = $pdo->query($sql, PDO::FETCH_ASSOC);
$tables = $result->fetchAll();
$table_count = count($tables);
$html =  '<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>' . $dbname . '--數(shù)據(jù)字典</title>
<style type="text/css">
    table caption, table th, table td {
        padding: 0.1em 0.5em 0.1em 0.5em;
        margin: 0.1em;
        vertical-align: top;
    }
    th {
        font-weight: bold;
        color: black;
        background: #D3DCE3;
    }
    table tr.odd th, .odd {
        background: #E5E5E5;
    }
    table tr.even th, .even {
        background: #f3f3f3;
    }
    .db_table{
        border-top:1px solid #333;
    }
    .title{font-weight:bold;}
</style>
</head>
<body>
<div style="text-align:center;background:#D3DCE3;font-size:19px;">
    <b>' . $dbname . '--數(shù)據(jù)字典</b>
</div>
<div style="background:#f3f3f3;text-align:center;">(注:共' . $table_count . '張表,按ctrl+F查找關(guān)鍵字)</div>' . "\n";
for ($i = 0; $i < $table_count; $i++) {
    $html .= '<ul type="square">' . "\n";
    $html .= '  <li>';
    $html .= ($i + 1) . '、表名:[' . $tables[$i]['Name'] . ']      注釋:' . $tables[$i]['Comment'];
    $html .= '</li>' . "\n";
    //查詢數(shù)據(jù)庫表字段信息
    $tab_name = $tables[$i]['Name'];
    $sql_tab = 'SHOW FULL FIELDS FROM `' . $tables[$i]['Name'] . '`';
    $result = $pdo->query($sql_tab, PDO::FETCH_ASSOC);
    $field_info = $result->fetchAll();
    $html .= '<li style="list-style: none outside none;"><table border="0" >';
    $html .= '<tr>
        <th style="width:110px">字段</th>
        <th>類型</th>
        <th>為空</th>
        <th>額外</th>
        <th>默認(rèn)</th>
        <th style="width:95px">字符集</th>
        <th>是否主鍵</th>
        <th>備注</th></tr>';
    for ($j = 0; $j < count($field_info); $j++) {
        $html .= '        <tr class="' . ($j % 2 == 0 ? "odd" : "even") . '">' . "\n";
        $html .= '          <td>' . $field_info[$j]['Field'] . '</td>' . "\n";
        $html .= '          <td>' . $field_info[$j]['Type'] . '</td>' . "\n";
        $html .= '          <td>' . $field_info[$j]['Null'] . '</td>' . "\n";
        $html .= '          <td>' . $field_info[$j]['Extra'] . '</td>' . "\n";
        $html .= '          <td>' . $field_info[$j]['Default'] . '</td>' . "\n";
        $html .= '          <td>' . $field_info[$j]['Collation'] . '</td>' . "\n";
        $html .= '          <td>' . $field_info[$j]['Key'] . '</td>' . "\n";
        $html .= '          <td>' . $field_info[$j]['Comment']. '</td>' . "\n";
        $html .= '        </tr>' . "\n";
    }
    $html .= '  </table></li>' . "\n";
    $html .= '</ul>' . "\n";
}
$html .= '</body>' . "\n";
$html .= '</html>' . "\n";
file_put_contents($dbname .'.html', $html);


使用方法

php dict.php -h 127.0.0.1 -u root -p 123456 -P 3306 -d blog_service


參數(shù)說明

-h mysql服務(wù)器地址 -u mysql用戶名 -p mysql密碼 -P mysql端口 -d mysql數(shù)據(jù)庫名

參數(shù)都有默認(rèn)值,-d參數(shù)必傳 最簡單的用法:

php dict.php -d blog_service

執(zhí)行命令后生成一個(gè)以數(shù)據(jù)庫名命名的html文件


分享到:
標(biāo)簽:mysql數(shù)據(jù)庫 mysql數(shù)據(jù)字典生成
用戶無頭像

網(wǎng)友整理

注冊(cè)時(shí)間:

網(wǎng)站:5 個(gè)   小程序:0 個(gè)  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會(huì)員

趕快注冊(cè)賬號(hào),推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨(dú)大挑戰(zhàn)2018-06-03

數(shù)獨(dú)一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學(xué)四六

運(yùn)動(dòng)步數(shù)有氧達(dá)人2018-06-03

記錄運(yùn)動(dòng)步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績?cè)u(píng)定2018-06-03

通用課目體育訓(xùn)練成績?cè)u(píng)定