数据库数据字典生成代码
2017-08-24 09:59
267 查看
header("Content-type:text/html;charset=utf-8"); //配置数据库 $dbserver="ip地址"; $dbusername="xxxx"; $dbpassword="xxxx"; $database="xxxx"; //其他配置 $mysql_conn=@mysql_connect("$dbserver","$dbusername","$dbpassword")ordie("Mysqlconnectiserror."); mysql_select_db($database,$mysql_conn); mysql_query('SETNAMESutf8',$mysql_conn); $table_result=mysql_query('showtables',$mysql_conn); $no_show_table=array();//不需要显示的表 $no_show_field=array();//不需要显示的字段 //取得所有的表名 while($row=mysql_fetch_array($table_result)){ if(!in_array($row[0],$no_show_table)){ $tables[]['TABLE_NAME']=$row[0]; } } //替换所以表的表前缀 if(@$_GET['prefix']){ $prefix='czzj'; foreach($tablesas$key=>$val){ $tableName=$val['TABLE_NAME']; $string=explode('_',$tableName); if($string[0]!=$prefix){ $string[0]=$prefix; $newTableName=implode('_',$string); mysql_query('renametable'.$tableName.'TO'.$newTableName); } } echo"替换成功!";exit(); } //循环取得所有表的备注及表中列消息 foreach($tablesas$k=>$v){ $sql='SELECT*FROM'; $sql.='INFORMATION_SCHEMA.TABLES'; $sql.='WHERE'; $sql.="table_name='{$v['TABLE_NAME']}'ANDtable_schema='{$database}'"; $table_result=mysql_query($sql,$mysql_conn); while($t=mysql_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']}'ANDtable_schema='{$database}'"; $fields=array(); $field_result=mysql_query($sql,$mysql_conn); while($t=mysql_fetch_array($field_result)){ $fields[]=$t; } $tables[$k]['COLUMN']=$fields; } mysql_close($mysql_conn); $html=''; //循环所有表 foreach($tablesas$k=>$v){ $html.='<h3>'.($k+1).'、'.$v['TABLE_COMMENT'].'('.$v['TABLE_NAME'].')</h3>'."\n"; $html.='<tableborder="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.='<tdclass="c1">'.$f['COLUMN_NAME'].'</td>'."\n"; $html.='<tdclass="c2">'.$f['COLUMN_TYPE'].'</td>'."\n"; $html.='<tdclass="c3">'.$f['COLUMN_DEFAULT'].'</td>'."\n"; $html.='<tdclass="c4">'.$f['IS_NULLABLE'].'</td>'."\n"; $html.='<tdclass="c5">'.($f['EXTRA']=='auto_increment'?'是':' ').'</td>'."\n"; $html.='<tdclass="c6">'.$f['COLUMN_COMMENT'].'</td>'."\n"; $html.='</tr>'."\n"; } } $html.='</tbody>'."\n"; $html.='</table>'."\n"; }?> <!doctypehtml> <html> <head> <metacharset="utf-8"> <title>数据库数据字典生成代码</title> <metaname="generator"content="ThinkDbV1.0"/> <metaname="copyright"content="2008-2014TensentInc."/> <style> body,td,th{font-family:"微软雅黑";font-size:14px;} .warp{margin:auto;width:900px;} .warph3{margin:0px;padding:0px;line-height:30px;margin-top:10px;} table{border-collapse:collapse;border:1pxsolid#CCC;background:#efefef;} tableth{text-align:left;font-weight:bold;height:26px;line-height:26px;font-size:14px;text-align:center;border:1pxsolid#CCC;padding:5px;} tabletd{height:20px;font-size:14px;border:1pxsolid#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> <divclass="warp"> <h1style="text-align:center;">数据库数据字典生成代码</h1> <?phpecho$html;?> </div> </body> </html>
相关文章推荐
- 数据库数据字典生成脚本 (Database Dictionary Generator)
- SQLserver数据库生成数据字典,数据库字段说明
- PHP连数据库生成数据字典
- sql2000,sql2005 数据字典生成代码
- [生成数据字典]取数据库表中字段的描述信息
- ASP.NET Web开发框架之五 设计时支持,代码生成,数据字典 ExtAspNet控件扩展
- 上传Excel数据到数据库中(Asp.net自动生成三层代码 第六集 )
- PowerDesigner逆向导入数据库,生成数据字典
- PowerDesigner根据数据库生成数据字典
- 将数据库里的表生成数据字典。
- 分享一个自己开发的数据字典与动态代码生成工具
- 数据库生成数据字典工具(PDMREAD)图解
- SQL Server 生成数据库代码,包含数据
- ASP.NET Web开发框架之五 设计时支持,代码生成,数据字典 ExtAspNet控件扩展
- php生成数据字典,代码
- poi+jdbc实现从数据库中导出表的数据字典结构(单个sheet和多个sheet供你选择),并且生成excel文档,作者:vipyhd
- 生成选择Toad导出数据字典,把数据库所有的表结构导出到htm中。
- php 生成mysql数据字典代码
- 一段由数据库结构生成相应数据对象的代码(1)(2) (3)--DataHelper
- PHP生成数据字典代码