Backup MySQL database with CodeIgniter

前端 未结 15 1530
一生所求
一生所求 2020-12-30 06:39

I have been looking into the user guide which came with CodeIgniter. I became very interested with the dbutil() method. Particularly the following line of code:

15条回答
  •  萌比男神i
    2020-12-30 07:27

    Try this, You can change format zip to gz if you like :)

    $this->load->dbutil();
    
    $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;
    
    $this->load->helper('file');
    write_file($save, $backup); 
    
    
    $this->load->helper('download');
    force_download($db_name, $backup);
    

提交回复
热议问题