• How can I retrieve values from one database server and store themin other database server using PHP?

    Answered

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

    Silver Member Asked on August 23, 2016 in Php.
    Add Comment
  • 1 Answer(s)
    Best answer

    WeWe 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 yousupply 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 whichindicates whether a link will be created or not. As we connect to the $db2 with this optional parameter set to ‘true’, so both link willremain live. Now the following query will execute successfully.$res3 = mysql_query(”query”,$db1);

    Silver Member Answered on August 23, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.