//-------------------------------------------------主体--------------------------------------------------
ljh_system_header();
/*
-------------------------配置数据库参数
*/
if(isset($HTTP_GET_VARS[setup])){
if($HTTP_GET_VARS[err]) echo "<p style='text-align:center'><font color=red>".urldecode($HTTP_GET_VARS[err])."</font></p>";
$para_setup_arr = ljh_get_para();
echo "<form name=f method=post action='".$HTTP_SERVER_VARS[PHP_SELF]."' style='text-align:center'>\n";
echo "<p style='font-weight:bold'>数据库参数配置</p>";
echo "数据库Ip[:Port]:<input name=para_ip value='".$para_setup_arr[0]."'><BR>\n";
echo "数据库登陆用户名:<input name=para_user value='".$para_setup_arr[1]."'><BR>\n";
echo "数据库登陆密&nbsp;&nbsp;码:<input name=para_password type=password><BR><BR>\n";
echo "<input type=submit name='para_setup' value='提交设置'>&nbsp;";
echo "<input type=button name='back_url' value='返回前一页' onclick='top.history.go(-1)'>";
echo "</form>\n";
ljh_system_bottom();
die();
}
if(isset($HTTP_POST_VARS[para_setup])){
if(@mysql_connect($HTTP_POST_VARS[para_ip],$HTTP_POST_VARS[para_user],$HTTP_POST_VARS[para_password])){
ljh_save_para($HTTP_POST_VARS[para_ip],$HTTP_POST_VARS[para_user],$HTTP_POST_VARS[para_password]);
header("Location:".$HTTP_SERVER_VARS[PHP_SELF]);
}else{
header("Location:".$HTTP_SERVER_VARS[PHP_SELF]."?setup&err=".urlencode("无法连接到数据库,请重新设置!"));
}
}/*
--------------------------生成结构表
*/
if($HTTP_POST_VARS[startGetStruts]){
$db_target = $HTTP_POST_VARS['db_name'];
$db_para_arr = ljh_get_para();
@mysql_pconnect($db_para_arr[0],$db_para_arr[1],$db_para_arr[2]) or header("Location:".$HTTP_SERVER_VARS[PHP_SELF]."?setup=1&err=".urlencode("无法连接数据库!请重新设置")); for($n=0;$n<count($HTTP_POST_VARS[table_arr]);$n++){
//--------------------fields
$table = $HTTP_POST_VARS[table_arr][$n];
$table_filed_rs = @mysql_db_query($db_target,"show fields from {$table}");
if(!$table_filed_rs){
echo "<p><font color=red>读取表{$table}结构失败:<BR>".mysql_error()."</font></p>";
continue;
}
echo "<p>&nbsp;</p><p style='font-weight:bold'>数据表{$table}结构:</p>\n";
echo "字段结构表:<BR>\n";
echo $para_table_style['innerHTML']."\n";
echo "\t".$para_table_style['headerTr']."\n";
foreach($para_table_field as $k=>$v){
echo "\t\t<TD width=".$v[1].">".$v[0]."</TD>\n";
}
echo "\t</TR>\n";
while($t=@mysql_fetch_array($table_filed_rs)){
echo "\t".$para_table_style['normalTr']."\n"; echo "\t\t<TD>";
echo $t[Field];
echo "\t\t</TD>\n"; echo "\t\t<TD>";
echo ljh_wordwrap($t['Type'], 12, "<br>");
echo "\t\t</TD>\n"; echo "\t\t<TD>";
echo ljh_get_scope_str($t['Type']);
echo "\t\t</TD>\n"; echo "\t\t<TD>";
echo strlen($tt=ljh_wordwrap($t['Default'], 12, "<br>"))==NULL?'空':$tt;
echo "\t\t</TD>\n"; echo "\t\t<TD>";
echo ljh_key_name($t['Key']).($t['Extra']=='auto_increment'?"<BR>自动增长":'');
echo "\t\t</TD>\n"; echo "\t\t<TD>";
echo '&nbsp;';
echo "\t\t</TD>\n"; echo "\t</TR>\n";
}
echo "</TABLE>\n";
if(!$HTTP_POST_VARS[if_index]) continue;
//-----------------index
$constraint_rs = @mysql_db_query($db_target,"show keys from $table");
if(!$constraint_rs){
echo "<p><font color=red>读取表{$table}索引失败:<BR>".mysql_error()."</font></p>";
continue;
}
$PK=array();$UK=array();$KEY=array();
while($con=mysql_fetch_object($constraint_rs)){
if($con->Key_name=="PRIMARY")
$PK[]=$con->Column_name;
if($con->Non_unique=="0"&&$con->Key_name!="PRIMARY")
$UK[$con->Key_name][]=$con->Column_name;
if($con->Non_unique=="1")
$KEY[$con->Key_name][]=$con->Column_name;
}
if(count($PK) || count($UK) || count($KEY)){
echo "<BR>索引结构表:<BR>\n";
echo $para_table_style['innerHTML']."\n";
echo "\t".$para_table_style['headerTr']."\n";
echo "\t\t<TD width=".$para_table_index['Type'][1].">".$para_table_index['Type'][0]."</TD>\n";
echo "\t\t<TD width=".$para_table_index['KeyName'][1].">".$para_table_index['KeyName'][0]."</TD>\n";
echo "\t\t<TD width=".$para_table_index['KeyField'][1].">".$para_table_index['KeyField'][0]."</TD>\n";
echo "\t</TR>\n"; if(count($PK)){
echo "\t".$para_table_style['normalTr']."\n";
echo "\t\t<TD>主键</TD>\n";
echo "\t\t<TD>PRIMARY</TD>\n";
echo "\t\t<TD>".ljh_wordwrap(implode($PK,","),35,"<BR>")."</TD>\n";
echo "\t</TR>\n";
}
if(count($UK)){
while(list($ke,$va)=@each($UK)){ //add UK
echo "\t".$para_table_style['normalTr']."\n";
echo "\t\t<TD>唯一</TD>\n";
echo "\t\t<TD>".$ke."</TD>\n";
echo "\t\t<TD>".ljh_wordwrap(implode($va,","),35,"<BR>")."</TD>\n";
echo "\t</TR>\n";
}
}
if(count($KEY)){
while(list($ke,$va)=@each($KEY)){ //add KEY
echo "\t".$para_table_style['normalTr']."\n";
echo "\t\t<TD>索引</TD>\n";
echo "\t\t<TD>".$ke."</TD>\n";
echo "\t\t<TD>".ljh_wordwrap(implode($va,","),35,"<BR>")."</TD>\n";
echo "\t</TR>\n";
}
}
$result=substr($result,0,-(strlen(",$enter")))."$enter);$enter";
echo "</TABLE>\n";
} }
echo "<p>&nbsp;</p>";
ljh_system_bottom();
die();
}//-------------------------------------默认,列出数据库
$db_para_arr = ljh_get_para();
if(!count($db_para_arr)) header("Location:".$HTTP_SERVER_VARS[PHP_SELF]."?setup&err=".urlencode("无法连接数据库,请设置数据库参数!"));
$db_link = @mysql_connect($db_para_arr[0],$db_para_arr[1],$db_para_arr[2]);
if(!$db_link) header("Location:".$HTTP_SERVER_VARS[PHP_SELF]."?setup&err=".urlencode("无法连接数据库,请设置数据库参数!"));
//获取某数据库的表
if($HTTP_GET_VARS[getTableDb]){
$db_table_rs = @mysql_list_tables($HTTP_GET_VARS[getTableDb]);
$db_tables_html .= "<table id='tb_".$HTTP_GET_VARS[getTableDb]."' border=1 cellspacing=0 cellpadding=0 borderColor=#000000 bordercolordark=#000000 style='border-collapse:collapse;font-size:12px;'>";
// $db_tables_html .= "<form name=frm"。" action='".$HTTP_POST_VARS[PHP_SELF]."' method=post>";
$db_tables_html .= "<TR bgColor=#E3E3E3 height=30 style='font-weight:bold;text-align:center'><td width=350 align=center>数据表排列顺序</td></TR>";
while(list($table)=mysql_fetch_row($db_table_rs)){
$db_tables_html .= "<tr><td align=center><input size=25 name='table_arr[]' value='".$table."'></td></tr>";
}
$db_tables_html .= "</table>";
echo "<script>parent.document.all.tableCase.innerHTML=\"".$db_tables_html."\";</script>";
echo "<script>parent.LJH_DynTbl('tb_".$HTTP_GET_VARS[getTableDb]."');\n</script>";
die();
}
$db_list = mysql_list_dbs($db_link);
while ($row = mysql_fetch_object($db_list)){
$db_opt.="<option value='".$row->Database."'>".$row->Database;
}
?>
<form name=frm action="<?=$HTTP_POST_VARS[PHP_SELF]?>" method=post>
<TABLE width=770 align=center>
<TR height=300>
<TD align=center width=40%>选择数据库:<BR>
<select name=db_name style="width:95%;height:95%" size="15" onchange="display_tbl(this.value)">
<?=$db_opt?>
</select>
</TD>
<TD width=60% id="tableCase">
&nbsp;
</TD>
</TR>
<TR>
<TD colspan=2 align=center>
选项:
<input type=checkbox checked name="if_index" value=1>
是否显示索引结构表
</TD>
</TR>
<TR>
<TD  colspan=2  align=center height=60>
<input type="submit" name="startGetStruts" value="列出当前数据库结构">
&nbsp;
<input type="button" name="resetPara" value="重新设置数据库参数" onclick="top.location='<?=$HTTP_SERVER_VARS[PHP_SELF]?>?setup'">
</TD>
</TR>
</TABLE>
</form>
<iframe name=frmGetTableList frameborder=0 width=0 height=0></iframe>

解决方案 »

  1.   

    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function display_tbl(tbl)
    {
    document.all.frmGetTableList.src = "<?=$HTTP_SEVER_VARS[PHP_SELF]?>?getTableDb="+tbl;
    return;
    var pre = "tb_";
    var s  = document.getElementsByTagName("TABLE");
    for(var i=0;i<s.length;i++){
    if(s[i].id.substr(0,pre.length)==pre){
    if(s[i].id==(pre+tbl)){
    s[i].style.display = "";
    }else{
    s[i].style.display = "none";
    }
    }
    }}
    function LJH_DynTbl(tId)
    {
    var a = document.getElementById(tId);
    a.colsNum = a.rows[a.rows.length-1].cells.length; //列数
    var optHtml = "<font color=blue size=4 style='font-weight:bold;cursor:hand' title='删此行'>-</font>&nbsp;&nbsp;"
    +"<font color=blue size=2 style='font-weight:bold;cursor:hand' title='上移一行'>↑</font>&nbsp;&nbsp;"
    +"<font color=blue size=2 style='font-weight:bold;cursor:hand' title='下移一行'>↓</font>"; function appendOptCell()
    {
    for(var n=0;n<a.rows.length;n++){
    a.rows[n].insertCell();
    a.rows[n].cells[a.colsNum].innerHTML = (n==0)?"&nbsp;":optHtml;
    if(n!=0){
    a.rows[n].cells[a.colsNum].attachEvent("onselectstart",returnfalse);
    var optNode = a.rows[n].cells[a.colsNum].childNodes;
    optNode[0].attachEvent("onclick",delRow);
    optNode[2].attachEvent("onclick",rowMovePre);
    optNode[4].attachEvent("onclick",rowMoveNext);
    }
    }
    }
    function delRow() //delete one line
    {
    if(a.rows.length<=2) return;
    var r = event.srcElement;
    while(r.tagName!="TR") r = r.parentElement;
    a.deleteRow(getRowIndex());
    }
    function rowMoveNext()
    {
    if(a.rows.length==(getRowIndex()+1)) return;
    a.moveRow(getRowIndex(),getRowIndex()+1);
    }
    function rowMovePre()
    {
    if(getRowIndex()==1) return;
    a.moveRow(getRowIndex(),getRowIndex()-1);
    }
    function getRowIndex()
    {
    var r = event.srcElement;
    while(r.tagName!="TR") r = r.parentElement;
    return r.rowIndex;
    }
    function returnfalse(){return false;};
    function init()
    {
    appendOptCell();
    }
    init();
    }
    document.body.onload = function()
    {
    document.frm.db_name.selectedIndex = 0;
    display_tbl(document.frm.db_name.options[0].value);
    }
    //-->
    </SCRIPT>
    <?ljh_system_bottom();?>
      

  2.   

    代码不难,比较繁琐而已生成的表格可以直接拷贝到word里面,很整齐
      

  3.   

    怎么我列出当前数据库结构的时候就是刷新页面啊, 谁的好用可以发给我一个吗
    [email protected]
      

  4.   

    后来又加了一些功能,可惜代码在公司,公司这两天不能上网,过两天再上传给大家To alexdream(阿辛) :
    什么刷新页面?什么意思?我这里电脑都没有出现什么异常现象啊?这么没人顶啊,大家用不上么?
      

  5.   

    主要加了以下功能:
    1.可以对每个表取中文名称,这样文档里面可以通过这个名称看懂表的含义
    2.添加了数据库所有表的简介表
    3.使用了标题,这样拷贝到WORD里面,可以根据这些标题生成索引目录过两天就上传,谢谢大家关心!
      

  6.   

    关注,楼主更新的时候麻烦往[email protected]给发一分,多谢了
      

  7.   

    好东西 楼主更新后 再麻烦给我来发份  [email protected]  谢谢啦
      

  8.   

    好吧,要的留下email但最好给一些建议,否则可能不会发出去:)
      

  9.   

    [email protected],我也要一份啊,现在正急需这个东西了。
      

  10.   

    [email protected]
    谢了,好东西!
      

  11.   

    楼上,你用的php版本?比较老的版本php可能有些不同,比如?setup的形式会被忽略留下email,v1.1解决了这个bug
      

  12.   

    留下email的,改天我给你们发广告哈。
      

  13.   

    兄弟,留个地址给下载吧,COPY代码容易出错哦!呵呵,还是给个妹er吧:[email protected]
      

  14.   

    兄弟,发给我一份吧[email protected]