如何获取数据库列表? [英] How to get a list of databases?

查看:94
本文介绍了如何获取数据库列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 PHP 中是否有一种方法可以通过使用 mysqli 列出所有可用数据库.以下内容在 MySQL 中正常运行(请参见 php文档):

I was wondering if there's a way in PHP to list all available databases by usage of mysqli. The following works smooth in MySQL (see php docs):

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
$db_list = mysql_list_dbs($link);

while ($row = mysql_fetch_object($db_list)) {
 echo $row->Database . "\n";
}  

我可以更改:

$db_list = mysql_list_dbs($link); // mysql

变成这样:

$db_list = mysqli_list_dbs($link); // mysqli

如果这不起作用,是否有可能将创建的 mysqli 连接转换为常规的 mysql 并继续获取/查询转换后的新连接?

If this is not working, would it be possible to convert a created mysqli connection into a regular mysql and continue fetching/querying on the new converted connection?

推荐答案

似乎没有可用的函数来执行此操作,但是您可以执行show databases;查询,返回的行将是可用的数据库

It doesn't appear as though there's a function available to do this, but you can execute a show databases; query and the rows returned will be the databases available.

这篇关于如何获取数据库列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆