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

Tell me what is the default session time in php?

735


Can you give example for trait in php?

732


Do you know how to get the ip address of the client?

735


Tell me how is it possible to propagate a session id?

798


How the web server interprets php and interacts with the client?

695


List types of array are available in php?

745


Is php 7 backwards compatible?

758


Can we override static method?

716


What is the best website to learn php?

705


Should I learn php before wordpress?

684


How do we get the current session id?

748


Is php closing tag necessary?

738


How many escape sequences are recognized in double-quoted strings in php?

721


What is the purpose of using php?

742


When a conditional statement is ended with an endif?

702