<?php
$dbhost1 = "10.0.11.211";
$dbuser1 = "root";
$dbpassword1 = "";
$db1 = "product";
$connection1 = mysqli_connect($dbhost1, $dbuser1, $dbpassword1) or die (mysqli_error());
mysqli_select_db($connection1, $db1);
//MySQL Server 2
$dbhost2 = "localhost";
$dbuser2 = "root";
$dbpassword2 = "";
$db2 = "product";
$connection2 = mysqli_connect($dbhost2, $dbuser2, $dbpassword2) or die (mysqli_error());
mysqli_select_db($connection2, $db2);
$sql = "insert into 10.0.11.211.product.inserting select * from localhost.product.inserting";
$result = mysqli_query($connection1, $sql);
if (!$result) {
echo "connection error";
}
?>
How can I correct this code? Actually I connected to servers at time.
You can setup federated tables, which is basically linking a table on one server to a table on another. Then use the federation to do your data transfers.
Then you can query it like any other table.
There are however a decent number of limitations you should read about including the remote password being stored in plain text. If this was a temporary setup purely for a once off copy, and the server isn't available to the public you have already minimised most of the risk associated with it though.