In this tutorial I will help you how to get your mysql database backup in your project file in CodeIgniter.
Codeigniter in a framework of PHP. It is a simple and easy framework. Anybody want to get database backup from your own project file when in run online or offline in a server.
In this tutorial help’s to you to get database backup from admin panel or back-end your project file. Follow me –
First: Get a button where you click and get database backup and give a link in your button and define a function name in your link call the function name in the controller page. follow the code in below Video help Click Here
View Page
<a href="Welcome/database_backup"><span class="glyphicon glyphicon-download"></span> Database Backup</a>
Second: Declare the function name in the Controller page and write the database backup code under function name. I write the code in below
Controller Page
$this->load->dbutil(); $db_format=array('format'=>'zip','filename'=>'my_db_backup.sql'); $backup=& $this->dbutil->backup($db_format); $dbname='backup-on-'.date('Y-m-d').'.zip'; $save='assets/db_backup/'.$dbname; write_file($save,$backup); force_download($dbname,$backup);
When you use this code you need some helper and library function, that are write under controller parent __construct
these are
function __construct() { parent::__construct(); $this->load->helper('url'); $this->load->helper('file'); $this->load->helper('download'); $this->load->library('zip'); }
Nice and excellent code, but I need a zip file “which is downloaded after clicking on backup button”, which should not open without authorize access. So how should I apply password to compressed zip file?