This question might seem a duplicate, However i tried all the examples to restore my database but none seems to work for me. I am trying to run a script that will restore my backup sql file to new database. I tried these lines to restore my database, but none seem to work.
$mysql_host = 'localhost';
$mysql_username = 'my_username';
$mysql_password = 'somepassword';
$db_name = 'test_db';
$source = 'C:/wamp/www/my_folder/test_db.sql';
$conn = mysql_connect( $mysql_host, $mysql_username, $mysql_password ) or die('Error connecting to MySQL server: ' . mysql_error());
mysql_query("CREATE DATABASE $db_name", $conn ) or die('Error connecting to MySQL server: ' . mysql_error());
restore_my_database( $mysql_host, $mysql_username, $mysql_password, $db_name, $source );
function restore_my_database( $mysql_host, $mysql_username, $mysql_password, $db_name, $source ) {
exec("mysql --opt -h $mysql_host -u $mysql_username -p $mysql_password $db_name < $source");
}
I also tried in function restore_my_database following lines
$command = "mysqldump --opt -h $mysql_host -u $mysql_username -p $mysql_password $db_name > $source";
system($command);
Upto database create, the code is working fine, but restore is not working. Can any one help me with the php restore code to restore my database. Thanks in advance
mysql_*functions (they're deprecated). Instead, consider using PDO or MySQLi - this article will help you decide which.mysqland themysqldumpcommands are not in the path for the user executing the script. Use the full path to these commands and try again.