刚写的MySQL数据库结构文档生成器(V1.0)
由于客户需要数据库结构文档,平时也没有写文档的习惯,所以写得比较很匆忙,如果大家发现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>";
}