top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How can I retrieve values from one database server and store them in other database server using PHP?

+5 votes
1,110 views

I Know that we can always fetch from one database server and rewrite it to another. But what is the simplest way to do this?

posted May 1, 2014 by Sachin Dahda

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button
Simply retrieve data from one server and store it in session variables,  then connect to other server and insert the data into the database.

1 Answer

+1 vote

We have to connect to the database server from php using the mysql_connect and store the connection identifier in a variable and then fetch the data from the server and then close the server connections using mysql_close() and then connect to another server and insert the value there.

  1. Connected to the first server fetch the data and stored in the $res variable

    $db=mysql_pconnect("host","username","pssword");
    mysql_select_db("dtabase name",$db);
    $query="select * from the table";
    $res=mysql_fetch_object(mysql_query($query));
    mysql_close($db)

  2. Connected to the second server

    $db=mysql_pconnect("secondhost","username","pssword");
    mysql_select_db("dtabase name",$db);
    $query="insert into tablename values($res)";
    mysql_close($db);

answer May 3, 2014 by Rahul Mahajan
Similar Questions
0 votes

I have created a form which take in values like
NAME
ADDRESS
EMAIL ID
PHOTO
PHONE NUMBER

i want to add these values into database, but i am having a problem in inserting the Image (photo).

+2 votes

how we can retrieve the unique values for the in a table without using the DISTINCT keyword

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...