Reputation: 823
I don't know how to write code to restore the .sql file whick backup from database using codeigniter. What should I do in controller to be able to restore it? I just create a form to select .sql file like this:
<form method="post" action="<?php echo base_url();?>main/reStore" enctype="multipart/form-data">
<p>Select Database: <input type="file" name="database"></p>
<p>Restore Database: <input type="submit" value="Restore">
</form>
and don't know what to do in controller
function reStore(){
$this->load->database();
}
Upvotes: 3
Views: 4647
Reputation: 21
I used this code
function restore_data()
{
$folder = FCPATH;
$folder = str_replace('\\', '/', $folder);
$path = $folder.'folder name of the .sql file/';
$sql_filename = 'file name.sql';
$sql_contents = file_get_contents($path.$sql_filename);
$sql_contents = explode(";", $sql_contents);
foreach($sql_contents as $query)
{
$pos = strpos($query,'ci_sessions');
var_dump($pos);
if($pos == false)
{
$result = $this->db->query($query);
}
else
{
continue;
}
}
}
Upvotes: 1
Reputation: 4951
Try to get an idea from this,may it helps you.
public function db_backup()
{
$this->load->dbutil();
$backup =& $this->dbutil->backup();
$this->load->helper('file');
write_file('your_file_path/your_DB.zip', $backup);
}
Upvotes: 0