2 回答
TA贡献1936条经验 获得超6个赞
从信息架构中获取信息,例如:
SELECT `SCHEMA_NAME` FROM `information_schema`.`SCHEMATA`;
还有更多关于数据库(模式)的信息
样本
MariaDB [(none)]> SELECT `SCHEMA_NAME` FROM `information_schema`.`SCHEMATA`;
+--------------------+
| SCHEMA_NAME |
+--------------------+
| bernd |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>
TA贡献1871条经验 获得超13个赞
只需遍历结果并打印它:
while ($arr = $stmt->fetch(PDO::FETCH_ASSOC)){
print_r($arr);
}
结果是您的本地主机中的数据库名称。例如:
Array
(
[Database] => mysql
)
Array
(
[Database] => performance_schema
)
Array
(
[Database] => phpmyadmin
)
编辑:
$databases = [];
while ($arr = $stmt->fetch(PDO::FETCH_ASSOC)){
$databases[] = $arr["Database"];
}
- 2 回答
- 0 关注
- 113 浏览
添加回答
举报