生成mysql数据字典
data_dictionary.php
<?php
/**
* 生成mysql数据字典
*/
header("Content-type: text/html; charset=utf-8");
//配置数据库
$dbserver = "127.0.0.1";
$dbusername = "root";
$dbpassword = "aigukj163";
$database = "aigu_api";
//其他配置
$mysql = new MySQLi("$dbserver", "$dbusername", "$dbpassword", "$database") or die("Mysql connect is error.");
$mysql -> set_charset('utf8');
$table_result = $mysql->query('show tables');
$no_show_table = array(); //不需要显示的表
$no_show_field = array(); //不需要显示的字段
//取得所有的表名
while($row = mysqli_fetch_array($table_result)){
if(!in_array($row[0],$no_show_table)){
$tables[]['TABLE_NAME'] = $row[0];
}
}
//替换所以表的表前缀
// if($_GET['prefix']){
// $prefix = 'sent_';
// foreach($tables as $key => $val){
// $tableName = $val['TABLE_NAME'];
// $string = explode('_',$tableName);
// if($string[0] != $prefix){
// $string[0] = $prefix;
// $newTableName = implode('_', $string);
// $mysql->query('rename table '.$tableName.' TO '.$newTableName);
// }
// }
// echo "替换成功!";exit();
// }
//循环取得所有表的备注及表中列消息
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 = mysqli_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 = mysqli_fetch_array($field_result) ) {
$fields[] = $t;
}
$tables[$k]['COLUMN'] = $fields;
}
$mysql->close($mysql_conn);$html = '';
//循环所有表
foreach ($tables as $k=>$v) {
$html .= ' <h3>' . ($k + 1) . '、' . $v['TABLE_COMMENT'] .' ('. $v['TABLE_NAME']. ')</h3>'."\n";
$html .= ' <table border="1" cellspacing="0" cellpadding="0" width="100%">'."\n";
$html .= ' <tbody>'."\n";
$html .= ' <tr>'."\n";
$html .= ' <th>字段名</th>'."\n";
$html .= ' <th>数据类型</th>'."\n";
$html .= ' <th>默认值</th>'."\n";
$html .= ' <th>允许非空</th>'."\n";
$html .= ' <th>自动递增</th>'."\n";
$html .= ' <th>备注</th>'."\n";
$html .= ' </tr>'."\n";
foreach ($v['COLUMN'] as $f) {
if(!@is_array($no_show_field[$v['TABLE_NAME']])){
$no_show_field[$v['TABLE_NAME']] = array();
}
if(!in_array($f['COLUMN_NAME'],$no_show_field[$v['TABLE_NAME']])){
$html .= ' <tr>'."\n";
$html .= ' <td class="c1">' . $f['COLUMN_NAME'] . '</td>'."\n";
$html .= ' <td class="c2">' . $f['COLUMN_TYPE'] . '</td>'."\n";
$html .= ' <td class="c3">' . $f['COLUMN_DEFAULT'] . '</td>'."\n";
$html .= ' <td class="c4">' . $f['IS_NULLABLE'] . '</td>'."\n";
$html .= ' <td class="c5">' . ($f['EXTRA']=='auto_increment'?'是':'&nbsp;') . '</td>'."\n";
$html .= ' <td class="c6">' . $f['COLUMN_COMMENT'] . '</td>'."\n";
$html .= ' </tr>'."\n";
}
}
$html .= ' </tbody>'."\n";
$html .= ' </table>'."\n";
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>数据库数据字典</title>
<style>
body, td, th { font-family: "微软雅黑"; font-size: 14px; }
.warp{margin:auto; width:900px;}
.warp h3{margin:0px; padding:0px; line-height:30px; margin-top:10px;}
table { border-collapse: collapse; border: 1px solid #CCC; background: #efefef; }
table th { text-align: left; font-weight: bold; height: 26px; line-height: 26px; font-size: 14px; text-align:center; border: 1px solid #CCC; padding:5px;}
table td { height: 20px; font-size: 14px; border: 1px solid #CCC; background-color: #fff; padding:5px;}
.c1 { width: 120px; }
.c2 { width: 120px; }
.c3 { width: 150px; }
.c4 { width: 80px; text-align:center;}
.c5 { width: 80px; text-align:center;}
.c6 { width: 270px; }
</style>
</head>
<body>
<div class="warp">
<h1 style="text-align:center;">数据库数据字典</h1>
<?php echo $html; ?>
</div>
</body>
</html>
生成mysql数据字典的更多相关文章
- 使用 PowerDesigner 和 PDMReader 逆向生成 MySQL 数据字典
下面提到的软件大家可以在下面的链接下载. 大家可以参考下面的操作录制视频来完成相关的操作. 使用 PowerDesigner 和 PDMReader 逆向生成 MySQL 数据字典.wmv_免费高速下 ...
- php 生成mysql数据字典代码
由于项目开发用了比较多的表 ,为了快速获取数据字典,通过php代码的方式来获取表结构和表注释.代码如下: <?php /** * 生成mysql数据字典 */ header ( "Co ...
- php生成mysql数据字典
<?php /** * 生成mysql数据字典 */ // 配置数据库 $database = array(); $database['DB_HOST'] = '127.0.0.1'; $dat ...
- php 生成mysql数据字典 (php5.5-5.6)
<?php /** * 生成mysql数据字典 */ //配置数据库 $dbserver = "127.0.0.1"; $dbusername = "root&qu ...
- [功能集锦] 003 - 一键生成mysql数据字典/数据库速查表
写在前面: 因为工作时候经常遇到半路接手项目的情况,由于年代久远,数据库字典这块经常缺失.故写此篇,以便复用,也希望对大家有点帮助. 随笔内容不高级,如有不妥,不吝指正. ps:有另一篇详细随笔可以参 ...
- 使用Navicat快速生成MySQL数据字典
1.通过information_schema.COLUMNS表 查询该表可得到所需字段信息 SELECT * FROM information_schema.COLUMNS; 如下图所示: 2.示例 ...
- 生成MySql数据库的数据字典代码参考
Code: /** * 生成mysql数据字典 */ //配置数据库 $dbserver = "127.0.0.1"; $dbusername = "root" ...
- PHP MYSQL数据字典
<?php /** * 生成mysql数据字典 */ header ( "Content-type: text/html; charset=utf-8" ); // 配置数据 ...
- Mysql数据字典导出
1.phpmyadmin中自带的数据字典导出 2.利用下面的脚本: <?php /** * 生成mysql数据字典 */ header("Content-type: text/html ...
随机推荐
- ElasticSearch入门之花落红尘(三)
上篇文章散仙介绍了ElasticSearch的入门安装和使用,那么本篇我们来看下,如何使用java api来和ElasticSearch进行交互,简单点说,就是实现一个增删改查,来找找入门的感觉. 在 ...
- 编程之法:面试和算法心得(字符串包含java实现)
内容全部来自编程之法:面试和算法心得一书,实现是自己写的使用的是java 题目描述 给定两个分别由字母组成的字符串A和字符串B,字符串B的长度比字符串A短.请问,如何最快地判断字符串B中所有字母是否都 ...
- 2018-8-10-win10-uwp-手把手教你使用-asp-dotnet-core-做-cs-程序
title author date CreateTime categories win10 uwp 手把手教你使用 asp dotnet core 做 cs 程序 lindexi 2018-08-10 ...
- Nmap扫描原理(上)
转自:https://blog.csdn.net/qq_34398519/article/details/89055991 Nmap是一款开源免费的网络发现(Network Discovery)和安全 ...
- 使用springmvc实现文件上传
该配置在javaweb上传文件篇中的基础上进行配置:https://www.cnblogs.com/flypig666/p/11745182.html 1.配置文件解析器,在springmvc.xml ...
- OpenGL学习笔记2017/8/29
OpenGL学习日志: 感谢doing5552 的OpenGL入门学习:http://www.cppblog.com/doing5552/archive/2009/01/08/71532.html 相 ...
- 关于vue项目报错:this relative module was not found
VScode编辑器增加了一行代码import func from './vue-temp/vue-editor-bridge'; 删除即可
- vue使用远程在线更新代码
一.main.js import Vue from 'vue' import App from './App' import router from './router' import Vuex fr ...
- vue v-for详解
1.Vue动态渲染列表------v-for用法详解: Html: <figure v-for="list in lists"> <div> ...
- Dockerfile镜像制作时间同步
1.问题描述 宿主机与容器时间相差8小时 2.原因 宿主机采用了CST时区,CST应该是指(China Shanghai Time,东八区时间)容器采用了UTC时区,UTC应该是指(Coordinat ...