gpt4 book ai didi

php - 来自同一服务器上的多个数据库的查询

转载 作者:行者123 更新时间:2023-11-30 00:12:10 25 4
gpt4 key购买 nike

我的信息分布在两个数据库中,并且希望使用 PHP 将一些信息放入一个网页上。

mysql_select_db('info',$conn);
mysql_select_db('users',$conn);
$query = "SELECT * FROM `sheet1` WHERE `mtr` = 989";
$result = mysql_query($query);

if (logged_in($user_data['mtr']) === true) {

while($row = mysql_fetch_array($result)) {
echo $row['nr_matricol'] . " " . $row['Numele']. " " . $row['D']. " " . $row['E']. " " . $row['F']. " " . $row['G']. " " . $row['H']. " " . $row['I']. " " . $row['J']. " " . $row['K']. " " . $row['L']. " " . $row['M']. " " . $row['N']. " " . $row['O']. " " . $row['P']. " " . $row['Q']. " " . $row['R']. " " . $row['S']. " " . $row['T']. " " . $row['U']. " " . $row['V']. " " . $row['W'];
echo "<br>";
}
}

我在第一个数据库和第二个数据库中有一个字段mtr。如何查询这两个数据库以仅显示一个用户(当前登录的用户)的数据?

我知道我必须改变这个

$query = "SELECT * FROM `sheet1` WHERE `mtr` = 989";`

但不知道如何。

最佳答案

从 2 个数据库中简单选择:

SELECT * 
FROM database_2.table_2
JOIN database_1.table_1
ON (database_2.table_2.some_field = database_1.table_1.some_other_field)
WHERE database_1.table_1.data_1 LIKE database_2.table_2.data_2

关于php - 来自同一服务器上的多个数据库的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23958744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com