Thanks to @Scoopy, I found that exec() was disabled my by hosting provider. However, I have solved my problem using the following code I found here :-
$db = mysql_connect ( 'localhost', 'username', 'pass' ) or die('not connected');
mysql_select_db( 'test', $db) or die('Not found');
$fp = fopen ( 'backup-file', 'r' );
$fetchData = fread ( $fp, filesize ( 'backup-file') );
$sqlInfo = explode ( ";\n", $fetchData); // explode dump sql as a array data
foreach ($sqlInfo AS $sqlData )
{
mysql_query ( $sqlData ) or die('Query not executed');
}
BUT, THE CODE IS DEPRECATED. So, I made up this code :-
$host = 'localhost';
$user = 'root';
$password = 'root';
$database = 'test';
$conn = new mysqli($host, $user, $password, $database);
$conn->autocommit(FALSE);
$fp = fopen('bkp-file', 'r');
$fetchData = fread($fp, filesize('bkp-file'));
$sqlInfo = explode(";\n", $fetchData); // explode dump sql as a array data
foreach ($sqlInfo AS $sqlData) {
$conn->query($sqlData);
}
$conn->commit();
$conn->close();
This code is perfect to use. It uses transactions to prevent multiple writes.
echo $cmd;and run the printed string in console. Most probably the problem is in new line symbol before<(if, of course, it is not there and you made it to format the code in question). Or path to$restore_fileis invalid.exec. Make sure yourerror_reportingis set toE_ALLand let us know what messages you are getting.phpinfo())