im试图打开与4个数据库的连接(同一主机)。这四个看起来都一样。
这是我的代码,但没有输出。为什么?有人有解决方案吗? 也许我的查询不正确?
谢谢!
<?php
$db = new mysqli("localhost","username","password");
mysqli_select_db('database1', $db);
mysqli_select_db('database2', $db);
mysqli_select_db('database3', $db);
mysqli_select_db('database4', $db);
$query = "SELECT A.name AS name1,
B.name AS name2,
C.name AS name3,
D.name AS name4
FROM database1.table1 A,
database2.table2 B,
database3.table3 C,
database4.table4 D";
$result = $db->query($query);
while($row = $result->fetch_assoc()) {
echo $row['name1'];
echo $row['name2'];
echo $row['name3'];
echo $row['name4'];
}
?>
答案 0 :(得分:0)
好。我有我的解决方案。一个连接,仅查询...!谢谢你们的提示!
$query = "
SELECT database1.table1.name as name FROM database1.table1
UNION ALL
SELECT database2.table2.name as name FROM database2.table2
UNION ALL
SELECT database3.table3.name as name FROM database3.table3
UNION ALL
SELECT database4.table4.name as name FROM database4.table4 order by name";