Saturday, 12 July 2014

How to restore mysql database using PHP script

If you want to restore your database with all tables and their data using the code of PHP this will helps you.

Here is the example of Database Restore PHP Script :


if(isset($_POST['submit'])) //Set Click event on form load


$host = "database_host_name"; 

$db_user = "database_user_name"; 

$db_pwd = "database_password";

$db_name = "database_name";



$db = mysqli_connect($host,$db_user,$db_pwd,$db_name);


        //File name you want to upload.

$filename = $_FILES["filemainname"]["name"]; 

$fp = fopen($filename, 'r' );

$fetchData = fread($fp, filesize($filename));

$sqlInfo = explode(";\n", $fetchData);

foreach ($sqlInfo AS $sqlData )


$datad = mysqli_query($db,$sqlData);


echo 'Done';



<form action="index.php" method="post" enctype="multipart/form-data">

<label for="file">Filename:</label>

<input type="file" name="filemainname" id="filemainname"><br>

<input type="submit" name="submit" value="Submit">


No comments: