有时候我们拿到别人的数据库,却没有数据字典,这个php小程序帮你轻松解决。
代码是网上找到的,当然,这段代码也仅仅是生成了数据字典,视图,存储过程等等是木有的哦。
$v) { $sql = 'select * from '; $sql .= 'information_schema.tables '; $sql .= 'where '; $sql .= table_name = '{$v['table_name']}' and table_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']}' and table_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 ($tables as $k=>$v) { //$html .= ''. $v['table_comment'] . ' '; $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 .= '
';}//输出echo ''.$title.'';echo ''.$title.'';echo $html;echo '';?>
运行后的结果:
http://www.bkjia.com/phpjc/664292.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/664292.htmltecharticle有时候我们拿到别人的数据库,却没有数据字典,这个php小程序帮你轻松解决。 代码是网上找到的,当然,这段代码也仅仅是生成了数据字...