0

I want to copy the database, create a new temporary one to work on only in php and once done want to update the original one. My problem is how to dump the original data into temporary database. I did that in qt creator, by create the new one and copy all the tables with data, is there any efficient way in php other than that.

Thanks in advance

Here is the code but with this only half of the database is exporting to a file

$qry_drop = "DROP DATABASE `temp-$pro_name`";
$re_drop = mysqli_query($connection, $qry_drop) or die(mysqli_error($connection));

$qry_temp_db = "CREATE DATABASE `temp-$pro_name`";
$result_temp = mysqli_query($connection, $qry_temp_db) or die(mysqli_error($connection));

exec("mysqldump -u *** -p* -h * test_empty > my_database_dump.sql", $output1, $return1);

echo $return1 . "<br/>";

if(!$return1){
    echo "Export succesfully";
}
else{
    echo "Unable to Export <br/>";
}

//exec("mysql -u sumit -p temp-test_empty < /172.16.0.150/var/www/html/my_database_dump.sql", $output, $return);
exec("mysql -u **** -p*** -h *** temp-test_empty < my_database_dump.sql", $output, $return);

echo $return . "<br/>";

if(!$return){
    echo "Import succesfully";
}
else{
    echo "Unable to import <br/>";
}
sumit
  • 11
  • 5
  • You mean like this? https://dev.mysql.com/doc/refman/5.6/en/mysqldump-copying-database.html This? https://stackoverflow.com/questions/675289/cloning-a-mysql-database-on-the-same-mysql-instance – David Jan 05 '18 at 14:32
  • It would be easier if you make a copy of the original database, make changes to the copy, rename the original to something else, and rename the copy to the original name. This way you do not have to bother with trying to synchronize the copy to the original. – MonkeyZeus Jan 05 '18 at 14:37
  • Anyways, check out https://stackoverflow.com/q/675289/2191572 – MonkeyZeus Jan 05 '18 at 14:37

0 Answers0