I have 2 separate databases. Both contain a column called "UID". I need to scan each row in database 1 and 2 and if "UID" matches then update database 2 with the rest of the row's information. Please advise the best way to go about this in PHP. I do have code an so far testing fine but want to be sure this is the best way to go about it
//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();