Backup MySQL database with CodeIgniter

Backup MySQL database with CodeIgniter

Published at - Aug 13, 2021

Use the following code to create the .zip file of your database and download.


$prefs = array(     
    'format'      => 'zip',             
    'filename'    => 'my_db_backup.sql'
$backup =& $this->dbutil->backup($prefs); 

$db_name = 'backup-on-'. date("Y-m-d-H-i-s") .'.zip';

$save = 'pathtobkfolder/'.$db_name;


write_file($save, $backup); 


force_download($db_name, $backup);

About author

Harendra Kanojiya

Hello, I am Harendra Kumar Kanojiya - Owner of this website and a Fullstack web developer. I have expertise in full-stack web development using Angular, PHP, Node JS, Python, Laravel, Codeigniter and, Other web technologies. I also love to write blogs on the latest web technology to keep me and others updated. Thank you for reading the articles.

Follow Us

Follow us on facebook Click Here

Facebook QR
Scan from mobile
Join our telegram channel Click Here
Telegram QR
Scan from mobile