-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptbackup.php
32 lines (30 loc) · 831 Bytes
/
scriptbackup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
include("../Templates/header.php");
require_once '../Templates/login.php';
$dumpfile = "/path/to/dump";
$con=mysqli_connect($host,$un,$pw,$db); //connect to DB
if(isset($_POST['backupfromscript']))//check if button was pressed on calling page
{
if(!file_exists($dumpfile))
{
echo "cannot find file";
}//if
else
{
$source = $dumpfile;
$sql = "DROP DATABASE IF EXISTS $db;";
$sql .= "Create DATABASE $db;";
$sql .= file_get_contents($source);
$qry = explode(";",$sql);
$arrlength = count($qry);
if($qry !=NULL)
{
for($i=0;$i<$arrlength - 1;$i++)
{
mysqli_select_db($con,$db);
mysqli_query($con, $qry[$i].";") or die("Failure to Execute: ". mysqli_error($con));
}//for
echo "Backup From Script File Successful";
}//if
}//else
}//if