How to Export Database using Codeigniter

Here I have developed an application in Codeigniter which will help you to take backup as per your wish wnenever you want to take backup. While most web hosting company do a daily backup of a customer’s database and site, relying on them to make backups and provide them at no cost is risky also.

public function export_database() {
	$this->load->dbutil();
	$prefs = array(
		'format' => 'zip',
		'filename' => 'crmdata.sql'
	);
	$backup = & $this->dbutil->backup($prefs);
	$db_name = 'crm-on-' . date("Y-m-d-H-i-s") . '.zip';
	$save = 'assets/database_backup/' . $db_name;
	$this->load->helper('file');
	write_file($save, $backup);
	$this->load->helper('download');
	force_download($db_name, $backup);
}

Leave a Reply

Your email address will not be published. Required fields are marked *