Hi I have write a code that can copy database table from one sever to another but the record of each table did not copy how to write a function that can copy tables and each record from one db server to another?
here's my sample code:
<?php
$dbNewDB = 'newdb';
$dbNewUser = 'newroot';
$dbNewUserPswd = 'newpass';
$dbConnect = mysql_connect('localhost', 'root', 'mypassword') or die('Couldn\'t connect to MySql:'.mysql_error());
$dbNewConnect = mysql_connect('localhost', $dbNewUser, $dbNewUserPswd) or die('Couldn\'t connect to MySql:'.mysql_error());
$sqlStatement = "SHOW TABLES FROM olddb";
$result = mysql_query($sqlStatement,$dbConnect) or die('Unable to get tables: '.mysql_error());
while($row = mysql_fetch_row($result))
{
//Drop table if exist
$sqlStatement = "DROP TABLE IF EXISTS " . $dbNewDB . "." . $row[0];
mysql_query($sqlStatement,$dbNewConnect) or die("Failed to delete: " . mysql_error());
//Create new table
$sqlStatement = "CREATE TABLE " . $dbNewDB . "." . $row[0] . " LIKE olddb." . $row[0];
echo "$sqlStatement [" . __METHOD__ . "]";
mysql_query($sqlStatement,$dbNewConnect)or die("Failed to create: ". mysql_error());
//Insert data
$sqlStatement = "INSERT INTO " . $dbNewDB . "." . $row[0] . " SELECT * FROM " . $dbNewDB . "." . $row[0];
echo "$sqlStatement [" . __METHOD__ . "]";
mysql_query($sqlStatement,$dbNewConnect)or die("Table copy failed: ".mysql_error());
echo "$row[0] copy done. [" . __METHOD__ . "]";
}
mysql_free_result($result);
mysql_close($dbConnect);
mysql_close($dbNewConnect);
?>
my code is already functional All i want to fixed to copy the records of each tables. Any idea?or help?
Thank you!