Location: PHPKode > projects > DDL CMS > Upload these files to your webspace/admin/restoredb.inc
								<h2>Restore Database</h2>
								<p>
<?php
	function showBackups()
	{
		echo '<table>' . "\n";
        echo 'Available Backups:<br><br>' . "\n";
        $backupArray = scandir(BASEDIR . 'backups/', 1);
        for($i = 0; $i < count($backupArray) - 2; $i++)
        {
            $fileNameArray = preg_split('/_/', $backupArray[$i], -1, PREG_SPLIT_NO_EMPTY);
            $fileName = preg_split('/\-/', $fileNameArray[2], -1, PREG_SPLIT_NO_EMPTY);
            $fileTime = preg_split('/\./', str_replace('-', ':', $fileNameArray[3]), -1, PREG_SPLIT_NO_EMPTY);
            $formattedTimestamp = $fileName[2] . '/' . $fileName[1] . '/' . $fileName[0] . ' at ' . $fileTime[0];
            echo '<tr>' . "\n";
            echo '<td>' . $formattedTimestamp . '</td>' . "\n";
			echo '<td>(' . HumanReadableFilesize(filesize(BASEDIR . 'backups/' . $backupArray[$i])) . ')</td>' . "\n";
            echo '<td><a href="ddl.php?go=restoredb&backup=' . $backupArray[$i] . '&backupAction=restore">[Restore]</a></td>' . "\n";
            echo '<td><a href="ddl.php?go=restoredb&backup=' . $backupArray[$i] . '&backupAction=delete">[Delete]</a></td>' . "\n";
            echo '</tr>' . "\n";
        }
    	echo '</table>' . "\n";
	}
	if(isset($_GET) && is_array($_GET) && count($_GET) > 0 && checkURLQuery('restoreDB.inc', $_GET) === TRUE)
	{
		if($_GET['backupAction'] == 'restore')
		{
			echo 'Database restored successfully.<br><br>';
			dbcom('DROP DATABASE ' . MYSQLDB . ';');
			$dbLink = mysql_connect(MYSQLHOST, MYSQLUSER, MYSQLPASSWD);
			mysql_query('CREATE DATABASE ' . MYSQLDB .' DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;', $dbLink);
			exec('mysql -u ' . MYSQLUSER . ' -h ' . MYSQLHOST . ' -D ' . MYSQLDB . ' --password="' . MYSQLPASSWD . '" < ' . BASEDIR . 'backups/' . $_GET['backup']);
		}
		elseif($_GET['backupAction'] == 'delete')
		{
			echo 'Deleted database restore file successfully.<br><br>';
			unlink(BASEDIR . 'backups/' . $_GET['backup']);
			showBackups();
		}
	}
	else
	{
		if(function_exists('exec') === TRUE)
		{
			showBackups();
		}
		else
		{
?>
								<p>Unable to restore backup files because exec() is disabled on this server.</p>
<?php
		}
	}
?>
Return current item: DDL CMS