如何使用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