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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to execute a php script from the command line?

556


What is local variable in php?

502


Explain different sorting function in php?

602


What is difference between echo and print in php?

493


How to do single and multi line comment in php?

552






I need to know about the courses which are useful in corporate companies.. especially php/mySQL, Java/j2ee, .NET.. also tell if any other courses are valuable

1514


What is php session and how it works?

520


What is different types of visibility?

531


Can you pass an array into a function?

556


what is mean by portal

1452


Tell me how is it possible to parse a configuration file?

503


What is the use of limit in mysql?

508


What does a special set of tags do in php?

544


Explain me what is x+ mode in fopen() used for?

539


What's the difference between accessing a class method via -> and via ::?

523