首页 > php框架 > 具体分析PHP获得所有数据库方法

具体分析PHP获得所有数据库方法


要查询系统中都存在哪些数据库,可使用mysql_list_dbs()函数,其语法格式如下:

resource mysql_list_dbs ([ resource $link_identifier ] )

mysql_list_dbs()函数返回的结果集中包含了MySQL服务器中所有的数据库,PHP获得所有数据库示例如下:

  1. < ?php  
  2. $connection=mysql_connect("localhost","root"
    ,"root") or die("连接服务器失败");  
  3. $db_list = mysql_list_dbs($connection);  
  4. while ($row = mysql_fetch_object
    ($db_list)) {  
  5. echo $row->Database . "< br>";  
  6. echo "< hr>";  
  7. }  
  8. mysql_close($connection);  
  9. ?> 

在上面PHP获得所有数据库代码中,循环输出结果集时用到了mysql_fetch_object()函数,mysql_fetch_object()函数和mysql_fetch_array()函数用法类似,不同的是 mysql_fetch_array()函数返回一个数组,而mysql_fetch_object()函数则返回一个对象。 mysql_fetch_object()函数的语法格式如下:

object mysql_fetch_object ( resource $result )


文章链接:http://www.phprm.com/frame/php1004038.html

随便收藏,请保留本文地址!

标签:none

发表留言