如何使用PDO获取PHP中的MySQL数据库列表? [英] How can I get a list of MySQL databases in PHP using PDO?

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

问题描述

我想知道如何使用PDO在PHP中获得MySQL数据库列表,而不必先连接到数据库(我的意思是dsn中没有dbname)?

I wonder how can I get the list of MySQL databases in PHP using PDO without having to connect to a database first ( I mean no dbname in dsn )?

通常,我曾经使用过mysql_list_dbs()函数,但是我不再以这种方式使用mysql.

Usually I used to use the function mysql_list_dbs() but I no longer use mysql this way.

推荐答案

您可以使用

show databases

或有关information_schema的查询:

or a query on the information_schema:

select schema_name from information_schema.schemata

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

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