简体   繁体   中英

Communication between the two servers to transfer data

Why can not establish a connection!! How to create a relationship between two tables in two database on separate server for information In fact, I want to get records from a table in second server and insert to another server in the table Table selection is correct:site1.com.class.users


this is my code:

$conn_server1=mysql_connect("site1.com","user","pass");
$db_server1=mysql_select_db("class",$conn_server1);

$conn_server2=mysql_connect("site2.com","user","pass");
$db_server2=mysql_select_db("class",$conn_server2);

$result=mysql_query("select * from site2.com.class.users where site2.com.class.users.mobile not in(select mobile form site1.com.class.users)",$conn_server1);

while(mysql_fetch_assoc($result))
mysql_query("insert into site1.com.class.users(name,family,phone1,phone2,mobile) select name,family,phone1,phone2,mobile from
site2.com.class.users",$conn_server1); 
    site2.com.class.users",$conn_server1);

You are trying to select data from connection 1 while using the connection 2. That's not going to work. And while you are at it. You might want to look into using MysqlI / PDO instead of the marked as deprecated mysql extension.

$res_server = mysql_query("SELECT name, family, phone1, phone2, mobile FROM users", $conn_server2);

while($row = mysql_fetch_assoc($res_server)) {
   // update / insert into on $conn_server1
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM