PHP 数据库表结构查看方法
内容摘要
这篇文章主要为大家详细介绍了PHP 数据库表结构查看方法,具有一定的参考价值,可以用来参考一下。
PHP查看数据库表结构,对此感兴趣的朋友,看看idc笔记做的技术笔记。经测试代码
PHP查看数据库表结构,对此感兴趣的朋友,看看idc笔记做的技术笔记。经测试代码
文章正文
这篇文章主要为大家详细介绍了PHP 数据库表结构查看方法,具有一定的参考价值,可以用来参考一下。
PHP查看数据库表结构,对此感兴趣的朋友,看看idc笔记做的技术笔记。经测试代码如下:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | <code class = "php" > <?php /** * 显示论坛表,结构 * * @param * @author php教程 www.idcnote.com **/ $dbhost = 'localhost' ; //服务器 $dbuser = 'root' ; //用户名 $dbpw = 'myoa888' ; //密码 $dbname = 'pipiqiu' ; //数据库名 $tablepre = 'pre_' ; //表前缀 header( "Content-type:text/html; char=gb2312" ); mysql_connect( $dbhost , $dbuser , $dbpw ) or die ( '数据库连接失败' ); mysql_query( "set names gb2312" ); mysql_select_db( $dbname ) or die ( '找不到数据库' ); echo '<style>*{font-size:12px;}.fenlei{width:250px;float:left;display:inline;}.pic{height:60px;float:left;display:inline;}</style>' ; $tb_names =mysql_list_tables( $dbname ); $tables = array (); //表名数组 /* 数据库所有表 */ while ( $row =mysql_fetch_row( $tb_names )){ $tables []= $row [0]; } echo $dbname . '该数据库含有<font color=red>' . count ( $tables ). '</font>个表,显示如下:<br>' ; echo '<div class="fenlei"></div>' ; foreach ( $tables as $v ){ echo '<div class="fenlei">' . $v . '</div>' ; } echo '</table>' ; /* 结构显示 */ echo '<p>======================= 结构显示 ======================= </p>' ; for ( $i =0; $i < count ( $tables ); $i ++){ $query =mysql_query( "select * from `" . $tables [ $i ]. "`" ); while ( $row =mysql_fetch_field( $query )){ $fd .= str_pad ( " " ,2). $row ->name. " " . $row ->type. "(" . $row ->max_length. ")," ; } $fd = substr ( $fd ,0,-1). "n" ; $fd = str_replace ( "," , ",n" , $fd ); echo '<table width= "100" border= "0" cellpadding= "8" cellspacing= "1" bgcolor= "#CCCCCC" style= "float:left;display:inline;margin-left:4px;margin-top:4px;" > <tr> <td align= "center" bgcolor= "#FFFFFF" ><strong> '.$tables[$i].' </strong></td> </tr> <tr> <td bgcolor= "#FFFFFF" > '.$fd.' </td> </tr> </table>'; unset( $fd ); } echo '<p style="clear:both;">======================= 显示完毕 ======================= </p>' ; ?> /*** 来自php教程(www.idcnote.com) ***/ </code> |
注:关于PHP 数据库表结构查看方法的内容就先介绍到这里,更多相关文章的可以留意
代码注释