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
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 |
What is the difference between super () and this ()?
Explain the value of the variable input is a string 1,2,3,4,5,6,7. How would you get the sum of the integers contained inside input?
How check field is empty or not in php?
What’s the special meaning of __sleep and __wakeup?
How do you trim spaces in excel?
How do I find out the number of parameters passed into function9?
Which MySQL function would you use to select a database?
What is the array in php?
how to make website package setup like desktop software setup ... that front end and backend can include in setup like single package...?
what is the abbrevation of PHP?
Is key exist in array php?
How to get tabels from database in php andd display it in the table form using codelgniter? plz help me