刚写的MySQL数据库结构文档生成器(V1.0)

phplover 2004-06-11 01:42:40
由于客户需要数据库结构文档,平时也没有写文档的习惯,所以写得比较很匆忙,如果大家发现bug,请即时回复或者给我短消息

为了方便,代码集中在一个文件中,可直接运行:
<?
ob_start();
error_reporting(0);
@set_time_limit(1000);

//---------------------------------参数配置-------------------------------------
$para_entry_key = "Author:Liu JH"; //加密解密key
$para_table_field = array( //名称,宽度(px)
'Field' => array('字段名称',120),
'Type' => array('类型',70),
'Scope' => array('范围',80),
'Default' => array('默认值',80),
'Peroperty' => array('属性',60),
'Memo' => array('字段说明',180),
);
$para_table_index = array(
'Type' => array('索引类型',60),
'KeyName' => array("名称",150),
'KeyField' => array("字段",250),
);
//表格样式定义
$para_table_style['innerHTML'] = "<TABLE border=1 cellspacing=0 cellpadding=0 borderColor=#000000 bordercolordark=#000000 style='border-collapse:collapse;font-size:12px'>";
$para_table_style['headerTr'] = "<TR bgColor=#E3E3E3 height=30 style='font-weight:bold;text-align:center'>";
$para_table_style['normalTr'] = "<TR height=25 style='text-align:center;'>";
//---------------------------------参数配置结束------------------------------------


//----------------------------------function
function ljh_wordwrap($str,$n,$break)//用于单字节字符串
{
return preg_replace("/([\w \(\),\.';\-:\|+\^~]{".$n."})/","\\1".$break,$str);
}
function ljh_key_name($key_en)
{
$key_arr = array("PRI"=>"主键","UNI"=>"唯一","MUL"=>"索引");
return $key_arr[$key_en];
}
function ljh_get_scope_str($scope)
{
if(preg_match("/^varchar\((\d+)\)$/i",$scope,$t)){//varchar
return "0~".$t[1]."字节";
}

$int_arr = array( //无符号,有符号
'int' =>array("0~2^32-1","-2^31~2^31-1"), 'tinyint' =>array("0~2^8-1","-2^7~2^7-1"),
'bigint' =>array("0~2^64-1","-2^63~2^63-1"), 'mediumint' =>array("0~2^24-1","-2^23~2^23-1"),
'smallint' =>array("0~2^16-1","-2^15~2^15-1"),
);
if(preg_match("/^(\w*int)/i",$scope,$t)){
return strpos($scope,"unsigned")?$int_arr[$t[1]][0]:$int_arr[$t[1]][1];
}

if(preg_match("/^enum\((.*)\)$/",$scope,$t)){//enum
return ljh_wordwrap(preg_replace("/(^')|('$)/i","",str_replace("','","|",$t[1])),12,"<BR>");
}

$text_arr = array(
'text' => "2^16字节", 'mediumtext'=> "2^24字节",
'longtext' => "2^32字节", 'tinytext' => "2^8字节",
);
if(preg_match("/text/i",$scope)){
return $text_arr[$scope];
}

$blob_arr = array(
'blob' => "2^16字节", 'mediumblob'=> "2^24字节",
'longblob' => "2^32字节", 'tinyblob' => "2^8字节",
);
if(preg_match("/blob/i",$scope)){
return $blob_arr[$scope];
}

if(preg_match("/^(float|double|decimal|numeric)\(?([^)]*)\)?/i",$scope,$t)){
$split = @explode(",",$t[2]);//print_r($split);
if($split[0]){
return ljh_wordwrap("-10^".($split[0]-$split[1])."+0.1^".$split[1]."~10^".($split[0]-$split[1])."-0.1^".$split[1],12,"<BR>")."<BR>精确".$split[1]."位小数";
}else{
if(strtolower($t[1])=="double") return "双精度浮点";
if(strtolower($t[1])=="float") return "单精度浮点";
return "-10^10+1~<BR>10^10-1";
}
}

if(preg_match("/^char\((\d+)\)$/i",$scope,$t)){ //char
return $t[1]."字节";
}

if(preg_match("/^set\((.*)\)$/",$scope,$t)){//enum
return ljh_wordwrap(str_replace("','",",",preg_replace("/(^')|('$)/i","",$t[1])),12,"<BR>");
}
return "-";
}
function web_keyED($txt,$encrypt_key)
{
$encrypt_key = md5($encrypt_key);
$ctr=0;
$tmp = "";
for ($i=0;$i<strlen($txt);$i++)
{
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
$ctr++;
}
return $tmp;
}

function web_encrypt($txt,$key)
{
$encrypt_key = md5($key);
$ctr=0;
$tmp = "";
for ($i=0;$i<strlen($txt);$i++)
{
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($encrypt_key,$ctr,1) .
(substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
$ctr++;
}
return web_keyED($tmp,$key);
}

function web_decrypt($txt,$key)
{
$txt = web_keyED($txt,$key);
$tmp = "";
for ($i=0;$i<strlen($txt);$i++)
{
$md5 = substr($txt,$i,1);
$i++;
$tmp.= (substr($txt,$i,1) ^ $md5);
}
return $tmp;
}
function ljh_save_para($ip,$user,$name)
{
$cookie = base64_encode(web_encrypt(@implode("_|_",array($ip,$user,$name)),$GLOBALS[para_entry_key]));
@setCookie("COOKIE_LJH_MYSQL_DOC_CREATOR",$cookie,time()+99999999,"/","",false);
}
function ljh_get_para()
{
$cookie_arr = @explode("_|_",web_decrypt(base64_decode($GLOBALS[HTTP_COOKIE_VARS][COOKIE_LJH_MYSQL_DOC_CREATOR]),$GLOBALS[para_entry_key]));
return $cookie_arr;
}
function ljh_system_header()
{
echo "<title>MySQL数据库文档结构生成器V1.0</title>\n";
echo "<style>body{font-size:13px;}</style>\n";
echo "<body topmargin=0 leftmargin=0 marginwidth=0 rightmargin=0>\n";
echo "<table width=100% border=0 cellspacing=0 bgColor=#9AB4F8 cellpadding=0 borderColor=#000000 bordercolordark=#000000 style='border-collapse:collapse;font-size:14px'>\n";
echo "<TR><TD align=center height=40 style='border-top:solid black 1px;border-bottom:solid black 1px'>MySQL数据库文档结构生成器V1.0</TD></TR>\n";
echo "</table>\n\n";
}
function ljh_system_bottom()
{
echo "<table width=100% border=0 cellspacing=0 bgColor=#9AB4F8 cellpadding=0 borderColor=#000000 bordercolordark=#000000 style='border-collapse:collapse;font-size:14px'>";
echo "<TR><TD align=center height=40 style='border-top:solid black 1px;border-bottom:solid black 1px'>版权所有©Liu JH</TD></TR>";
echo "</table>";
}
...全文
539 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
pk3g9a 2004-06-18
  • 打赏
  • 举报
回复
兄弟,发给我一份吧

joesenhong@yahoo.com.cn
phplover 2004-06-17
  • 打赏
  • 举报
回复
已经发送
missago 2004-06-16
  • 打赏
  • 举报
回复
zheyong@msn.com
AlexJia2046 2004-06-16
  • 打赏
  • 举报
回复
haidong@126.com
龙威 2004-06-16
  • 打赏
  • 举报
回复
兄弟,留个地址给下载吧,COPY代码容易出错哦!

呵呵,还是给个妹er吧:ljcao@eyou.com
zairwolf 2004-06-16
  • 打赏
  • 举报
回复
留下email的,改天我给你们发广告哈。
goldce 2004-06-15
  • 打赏
  • 举报
回复
goldce2008@hotmail.com

嘻嘻
uuq 2004-06-14
  • 打赏
  • 举报
回复
好,收下
phplover 2004-06-14
  • 打赏
  • 举报
回复
已经发给楼上四位了
pangxie520 2004-06-14
  • 打赏
  • 举报
回复
linbo628@163.com
谢了,好东西!
wyx726 2004-06-14
  • 打赏
  • 举报
回复
wyx@zwon.net,我也要一份啊,现在正急需这个东西了。
phplover 2004-06-14
  • 打赏
  • 举报
回复
楼上,你用的php版本?比较老的版本php可能有些不同,比如?setup的形式会被忽略

留下email,v1.1解决了这个bug
wyx726 2004-06-14
  • 打赏
  • 举报
回复
我的运行不起了啊,提示输入用户名和密码,但一输入后,就出现页面打不开,是什么问题啊。
phplover 2004-06-13
  • 打赏
  • 举报
回复
好吧,要的留下email

但最好给一些建议,否则可能不会发出去:)
armi514 2004-06-13
  • 打赏
  • 举报
回复
好东西 楼主更新后 再麻烦给我来发份  armi514@sohu.com 谢谢啦
yibotiemen 2004-06-12
  • 打赏
  • 举报
回复
关注,楼主更新的时候麻烦往etng@263.net给发一分,多谢了
phplover 2004-06-12
  • 打赏
  • 举报
回复
主要加了以下功能:
1.可以对每个表取中文名称,这样文档里面可以通过这个名称看懂表的含义
2.添加了数据库所有表的简介表
3.使用了标题,这样拷贝到WORD里面,可以根据这些标题生成索引目录

过两天就上传,谢谢大家关心!
phplover 2004-06-12
  • 打赏
  • 举报
回复
后来又加了一些功能,可惜代码在公司,公司这两天不能上网,过两天再上传给大家

To alexdream(阿辛) :
什么刷新页面?什么意思?我这里电脑都没有出现什么异常现象啊?

这么没人顶啊,大家用不上么?
AlexJia2046 2004-06-11
  • 打赏
  • 举报
回复
怎么我列出当前数据库结构的时候就是刷新页面啊, 谁的好用可以发给我一个吗
haidong@126.com
xter 2004-06-11
  • 打赏
  • 举报
回复
猛啊
加载更多回复(5)

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧