// +----------------------------------------------------------------------
// | zbMysql
// +----------------------------------------------------------------------
// | Copyright (c) 2012-2016 http://www.xazbkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: honor
// +----------------------------------------------------------------------
//访问方法 /mysql.php?pwd=******&table=表名为空所有表
session_start();
header("Content-type:text/html;charset=utf-8");
/**
* 生成mysql数据字典
*/
// 配置数据库
$database = array();
$password = '327677';//访问密码GET['pwd'] 传输
$database['DB_HOST'] = '127.0.0.1';
$database['DB_NAME'] = 'shopcrmeb';//数据库名称
$database['DB_USER'] = 'shopcrmeb';//用户名
$database['DB_PWD'] = '5FYGH5d6zWZffrmA';//密码
$char_set = 'UTF8';//数据库编码
date_default_timezone_set('Asia/Shanghai');
$mysql_conn = @mysqli_connect("{$database['DB_HOST']}", "{$database['DB_USER']}", "{$database['DB_PWD']}") or die("Mysql connect is error.");
mysqli_select_db($mysql_conn,$database['DB_NAME']);
$result = mysqli_query($mysql_conn,'show tables');
mysqli_query($mysql_conn,'SET NAMES '.$char_set);
$pwd = !empty($_GET['pwd'])?$_GET['pwd']:$_SESSION['pwd'];
if($password != $pwd)exit('无权访问');
$_SESSION['pwd'] = $pwd;
if($_GET['table'])
{
$tables[]['TABLE_NAME'] = $_GET['table'];
}else{
// 取得所有表名
while ($row = mysqli_fetch_array($result))
{
$tables[]['TABLE_NAME'] = $row[0];
}
}
// 循环取得所有表的备注及表中列消息
foreach($tables as $k => $v)
{
$sql = 'SELECT * FROM ';
$sql .= 'INFORMATION_SCHEMA.TABLES ';
$sql .= 'WHERE ';
$sql .= "table_name = '{$v['TABLE_NAME']}' AND table_schema = '{$database['DB_NAME']}'";
$table_result = mysqli_query($mysql_conn,$sql);
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['DB_NAME']}'";
$fields = array();
$field_result = mysqli_query($mysql_conn,$sql);
while ($t = mysqli_fetch_array($field_result))
{
$fields[] = $t;
}
$tables[$k]['COLUMN'] = $fields;
}
mysqli_close($mysql_conn);
//print_r($tables);
$html = '';
if(isset($_GET['table']))
{
$html .= '
表结构
';$html .= '
生成时间:' . date('Y-m-d H:i:s') . '
';// 循环所有表
foreach($tables as $k => $v)
{
$html .= '
$html .= '
表名:' . $v['TABLE_NAME'] . ' ------- ' . $v['TABLE_COMMENT'] . '';$html .= '
字段名数据类型默认值允许非空自动递增备注';$html .= '';
foreach($v['COLUMN'] AS $f)
{
$html .= '
' . $f['COLUMN_NAME'] . '';$html .= '
' . $f['COLUMN_TYPE'] . '';$html .= '
' . $f['COLUMN_DEFAULT'] . '';$html .= '
' . $f['IS_NULLABLE'] . '';$html .= '
' . ($f['EXTRA'] == 'auto_increment'?'是':' ') . '';$html .= '
' . $f['COLUMN_COMMENT'] . '';$html .= '';
}
$html .= '
';$html .= '
总共:' . count($v['COLUMN']) . '个字段
';$html .= '