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() {
	$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;
	write_file($save, $backup);
	force_download($db_name, $backup);

Leave a Reply

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