Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-13 11:11:54
Original
1502 people have browsed it

要查询系统中都存在哪些数据库,可使用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 )


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!