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

Answers were Sorted based on User's Feedback



How can I retrieve values from one database server and store them in other database server using PH..

Answer / vijaya

we can always fetch from one database and rewrite to
another. Here is a nice solution of it.

$db1 = mysql_connect(”host”,”user”,”pwd”)
mysql_select_db(”db1″, $db1);
$res1 = mysql_query(”query”,$db1);
$db2 = mysql_connect(”host”,”user”,”pwd”)
mysql_select_db(”db2″, $db2);
$res2 = mysql_query(”query”,$db2);At this point you can only
fetch records from you previous ResultSet,

i.e $res1 - But you cannot execute new query in $db1, even
if you supply the link as because the link was overwritten
by the new db.so at this point the following script will fail

$res3 = mysql_query(”query”,$db1); //this will failSo how to
solve that?

Take a look below.

$db1 = mysql_connect(”host”,”user”,”pwd”)
mysql_select_db(”db1″, $db1);
$res1 = mysql_query(”query”,$db1);

$db2 = mysql_connect(”host”,”user”,”pwd”, true)
mysql_select_db(”db2″, $db2);
$res2 = mysql_query(”query”,$db2);

So mysql_connect has another optional boolean parameter
which indicates whether a link will be created or not. as we
connect to the $db2 with this optional parameter set to
‘true’, so both link will remain live.

now the following query will execute successfully.
$res3 = mysql_query(”query”,$db1);

Is This Answer Correct ?    14 Yes 4 No

How can I retrieve values from one database server and store them in other database server using PH..

Answer / ravinder

by using import and export

Is This Answer Correct ?    1 Yes 15 No

Post New Answer

More PHP Interview Questions

what is this error "Call to unsupported or undefined function mysql_connect();" and when you will get this?

2 Answers  


What is php array function?

0 Answers  


is anybody upload more than 100mb file using PHP upload script in ONLINE SERVER (using .htaccess file)? please give some idea...

1 Answers  


If i make my selection in State Dropdown list, i would the City and ZipCode dropdown list to be automatically reupdated based on the State i select.(This to avoid the user select a City or Zipcode that does not correspond to the State previously selected.)

2 Answers   CMC, PHP,


Which database is best for php?

0 Answers  






Draw the architecture of Zend engine?

4 Answers  


what is used for tmp table in oracle?

0 Answers  


How can you associate a variable with a session?

0 Answers  


How to execute an sql query?

0 Answers  


Which is better php or wordpress?

0 Answers  


What are sql injections, how do you prevent them and what are the best practices?

0 Answers  


Which is the dependent variable?

0 Answers  


Categories