我有2个独立的数据库。两者都包含一个称为“ UID”的列。我需要扫描数据库1和2中的每一行,如果“ UID”匹配,则用该行的其余信息更新数据库2。请建议最好的方法来解决此问题。到目前为止,我的代码确实可以很好地进行测试,但是要确保这是最好的方法
//database 1 query
$query_db1 = mysqli_query($conn_db1, "SELECT *
FROM `table`.`list`
WHERE `list`.`reg_date` >= DATE_SUB(NOW(),INTERVAL 24 HOUR)");
$counter = 0;
while ($row_db1 = mysqli_fetch_assoc($query_db1)) {
//find records, compare uid, if found then update status
//prepare update query into database 2
$stmt = $conn_db2->prepare("UPDATE TABLE SET Disposition=? WHERE UID=?");
$stmt->bind_param("ss", $row_db1['status'], $row_db1['UID']);
if ($stmt->execute()) {
echo "success, ";
if($stmt->affected_rows === 1){
$counter++;
}
} else {
echo "Error connecting to database";
}
}
echo "Rows updated: $counter <br>";
$stmt->close();