gpt4 book ai didi

php - 使用 php 从具有相同表的同一服务器查找 2 个 mysql 数据库中的差异

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

程序是从具有相同表的同一服务器中查找 2 db 的差异,并使用 php 显示表中的差异。在这里我发现很难选择数据库名称,我试图通过表单方法获取数据库名称。

<html>
<head>
<title>Connecting db</title>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<form method="post" action="" >
<label>db1 :</label>
<input type="text" name="db1 name">
<input type="submit" name="submit" value="submit">
<br><br>
<label>db2 :</label>
<input type="text" name="db2 name">
<input type="submit" name="submit" value="submit">
</form>
<?php
if(isset($_POST["submit"])){$servername = "servername";
$username = "username";
$password = "password";
$dbname = "db";

$db1 = $_POST["db1 name"];
$db2 = $_POST["db2 name"];

// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT application_id,application_name\n"
. "FROM "($db1)".applications\n"
. "WHERE(\n"
. " application_id NOT IN \n"
. " (SELECT application_id FROM "($db2)".applications)\n"
. " )\n"
. "GROUP BY application_id LIMIT 0, 30 ";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
echo "<table><tr><th>APPLICATION ID</th><th>APPLICATION Name</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["application_id"]."</td><td>".$row["application_name"].."</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
}
?>
</body>
</html>

最佳答案

尝试这种连接

$conn = mysqli_connect("hostname","username","password");
mysqli_select_db("db1",$conn);
mysqli_select_db("db2",$conn);

关于php - 使用 php 从具有相同表的同一服务器查找 2 个 mysql 数据库中的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39075387/

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