php - 循环访问名称存储在主数据库中的数据库
问题描述
所以我有一个主数据库,其中存储了其他数据库的名称。我需要以某种连接方式循环存储在主数据库中的所有数据库的槽表。status != 2
我需要站点数据库中使用 PHP 和 MySQLi的所有行的数组。
主要的看起来像这样:
main.stations
+----+-----------------+------+
| ID | station name | db |
+----+-----------------+------+
| 1 | Name of station | db_1 |
| 2 | Name again | db_2 |
| 3 | Name | db_3 |
+----+-----------------+------+
所有三个站都有一个指定的数据库,其名称在列中说明main.stations.db
该站的数据库有两个表,我需要循环遍历并获取所有行status != 2
。这两个表如下所示(以 db_1 为例):
db_1.salesReport
+----+----------+--------+
| ID | name | status |
+----+----------+--------+
| 1 | Report 1 | 1 |
| 2 | Report 2 | 0 |
| 3 | Report 3 | 2 |
+----+----------+--------+
db_1.fuelReport
+----+----------+--------+
| ID | name | status |
+----+----------+--------+
| 1 | Report 1 | 1 |
| 2 | Report 2 | 0 |
| 3 | Report 3 | 2 |
+----+----------+--------+
我的问题是;有没有办法根据来自另一个数据库的数据库名称循环访问数据库?(当然假设用户有权访问所有数据库)我不想在基于站点的阵列中添加另一层。我希望子数据库中的每一行都是我的数组中的顶级元素,包括来自车站的所有信息。
编辑 输出必须看起来像这样
0:{
stationID: 1
station name: Name of stations,
fromDb: salesReport //this doesn't have to be dynamically stated
name: Report 1,
status: 1
},
1:{
stationID: 1
station name: Name of stations,
fromDb: fuelReport
name: Report 1,
status: 1
},
2:{
stationID: 1
station name: Name of stations,
fromDb: salesReport
name: Report 2,
status: 0
},
3:{
stationID: 2
station name: Name again,
fromDb: salesReport
name: Report 2,
status: 0
},
等等..
解决方案
推荐阅读
- python - 在 R 或 Python 中表示优势比和 p 值的好方法
- c++ - 如何让 std::istream 从键盘获取输入(如 std::cin)?
- r - 使用 for 循环在环境中创建新数据集
- c++ - 对象错误地显示为参考?
- visual-studio - 如何在 Visual Studio 和 CMake 中使用 clang-tidy?
- javascript - document.getElementById 用于“div”警报 [object HTMLDivElement] 而不是“thisDiv”
- python - 在 Ubuntu 18.04 上使用 pip 安装 pydoop 时出错
- arrays - [Powershell/Sharepoint]有人可以查看我的脚本以删除超过 7 天的 Sharepoint 列表项吗?获取'无法索引到空数组'
- python - 如何找到用于 kivy 的特定颜色的代码?
- python - gcc c++ stl pretty printer - 手动调用并仅询问大小