I want to copy certain tables from server to server b.
How do I make it fastly and efficiently with PHP?
I wrote below my current start, but it may not be the best approach.
Perttu Pulkkinen, FINLAND
----------------------------
<?
$host_A = "xxx";
$user_A = "xxx";
$pass_A = "xxx";
$base_A = "xxx";
$host_B = "yyy";
$user_B = "yyy";
$pass_B = "yyy";
$base_B = "yyy";
$tables = array(""this", that", "those", "them");
$link_A = mysql_connect($ host_A, $user_A, $pass_A);
or die("Yhteys tietokantaan A epäonnistui! : " . mysql_error());
$link_B = mysql_connect($ host_B, $user_B, $pass_B);
or die("Yhteys tietokantaan B epäonnistui! : " . mysql_error());
mysql_select_db ($base_A, $link_A) or die("Tietokanna n A valinta
epäonnistui!");
mysql_select_db ($base_B, $link_B) or die("Tietokanna n B valinta
epäonnistui!");
foreach($tables as $table)
{
$qid_A = mysql_query("SE LECT * FROM $table", $link_A)
or die("Haku tietokantaan A epäonnistui! : " . mysql_error());
$qid_DEL_B = mysql_query("DE LETE FROM $table", $link_B):
or die("Taulun tyhjennys tietokannassa B epäonnistui! : " .
mysql_error());
// THIS PART IS MAYBE STUPID, PAINFUL-TO-DO AND UNEEFICIENT
while($row = mysql_fetch_row ($qid_A))
{
$stuff = somehow_formula te_row($row); // ?????? not implemented
$qid_B = mysql_query("IN SERT INTO $table $stuff") or die("");
}
}
?>
How do I make it fastly and efficiently with PHP?
I wrote below my current start, but it may not be the best approach.
Perttu Pulkkinen, FINLAND
----------------------------
<?
$host_A = "xxx";
$user_A = "xxx";
$pass_A = "xxx";
$base_A = "xxx";
$host_B = "yyy";
$user_B = "yyy";
$pass_B = "yyy";
$base_B = "yyy";
$tables = array(""this", that", "those", "them");
$link_A = mysql_connect($ host_A, $user_A, $pass_A);
or die("Yhteys tietokantaan A epäonnistui! : " . mysql_error());
$link_B = mysql_connect($ host_B, $user_B, $pass_B);
or die("Yhteys tietokantaan B epäonnistui! : " . mysql_error());
mysql_select_db ($base_A, $link_A) or die("Tietokanna n A valinta
epäonnistui!");
mysql_select_db ($base_B, $link_B) or die("Tietokanna n B valinta
epäonnistui!");
foreach($tables as $table)
{
$qid_A = mysql_query("SE LECT * FROM $table", $link_A)
or die("Haku tietokantaan A epäonnistui! : " . mysql_error());
$qid_DEL_B = mysql_query("DE LETE FROM $table", $link_B):
or die("Taulun tyhjennys tietokannassa B epäonnistui! : " .
mysql_error());
// THIS PART IS MAYBE STUPID, PAINFUL-TO-DO AND UNEEFICIENT
while($row = mysql_fetch_row ($qid_A))
{
$stuff = somehow_formula te_row($row); // ?????? not implemented
$qid_B = mysql_query("IN SERT INTO $table $stuff") or die("");
}
}
?>
Comment