码迷,mamicode.com
首页 > 数据库 > 详细

php -- 数据库信息

时间:2014-05-25 02:23:45      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   c   code   java   

----- 023-dbinfo.php -----

bubuko.com,布布扣
 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta http-equiv="content-type" content="text/html; charset=utf-8">
 5     <title>MySQL数据库信息</title>
 6 </head>
 7 <body>
 8 <h2>MySQL数据库信息</h2>
 9 <pre style="font-family:微软雅黑; font-size:14pt">
10 <?php
11 /*
12     mysql_connect() 执行连接
13     mysql_query() 执行SQL语句
14     mysql_result(资源,行,[列])查询具体数据
15     mysql_num_rows()返回行数
16     mysql_num_fields()返回列数
17     mysql_fetch_row|assoc|array 返回一行,指针后移
18     mysql_fetch_field($result, 列索引) 返回列信息
19 */
20 
21     $con = @mysql_connect("localhost", "root", "root") or die("连接失败");
22     //$dblist = mysql_list_dbs($con);系统不推荐
23     $dblist = mysql_query("SHOW DATABASES");
24     echo "共有数据库:", mysql_num_rows($dblist), "个。\n";
25     while($s = mysql_fetch_row($dblist))
26         echo $s[0], ", ";
27     echo "\n";
28 
29     mysql_query("USE world");
30     $tblist = mysql_query("SHOW TABLES");
31     echo "共有数据表:", mysql_num_rows($tblist), "个。\n";
32     while($s = mysql_fetch_row($tblist))
33         echo $s[0], "  ";
34     echo "\n第三个表:", mysql_result($tblist, 2, 0), "\n";
35 
36     $result = mysql_query("SELECT * FROM COUNTRY");
37     $s = mysql_fetch_field($result, 5);
38     echo "数据表共有", mysql_num_fields($result), "列\n";
39     echo "第六列的字段信息:", var_export($s), "\n";
40     echo "列长:", mysql_field_len($result, 5), "\n";
41     echo "列名:", mysql_field_name($result, 5), "\n";
42     echo "列数据类型:", mysql_field_type($result, 5), "\n";
43 ?>
44 </pre>
45 </body>
46 </html>
bubuko.com,布布扣

bubuko.com,布布扣

php -- 数据库信息,布布扣,bubuko.com

php -- 数据库信息

标签:style   class   blog   c   code   java   

原文地址:http://www.cnblogs.com/baijifeilong/p/3750456.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!