1

我的 phpmyadmin 有这些数据库,看起来像这样:

demo_db_1
information_schema
mysql
performance_schema
demo_db_2
test_db_1
test_db_2

如何获取所有自定义数据库的列表?

含义:当我运行文件 test.php 时,我希望看到一个类似的列表

demo_db_1
demo_db_1
test_db_1
test_db_2

我不想连接到任何数据库。只想要所有创建的数据库的列表。我怎样才能做到这一点?

提前致谢

4

2 回答 2

5

Call a mysql query with mysql_query("show databases;");

You can get list of the databases you have access to with:

SHOW DATABASES;

If you want to get the list for some other user than the user you're logged in as, you have to query the mysql.db table.

于 2013-03-05T07:42:42.950 回答
1

您可以使用以下代码:

<?php
    //mysql_connect('HostName','UserName','Password');
    mysql_connect('localhost','root','');
    $database = mysql_query("show databases;");
    while($data = mysql_fetch_assoc($database))
    {
    $fetch[] = $data;
    }
    print "<pre>";
    print_r($fetch);
?>
于 2013-03-05T08:30:07.723 回答