Backup MySQL database with CodeIgniter

前端 未结 15 1571
一生所求
一生所求 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条回答
  •  清酒与你
    2020-12-30 07:04

    The problem is that you are trying to backup the database very early during bootstrapping.

    I ran into the same problem when I tried to hack CodeIgniter into backing up my database using:

    $prefs = array(
                'ignore'=> array('codes_cdt','codes_cpt','codes_icd10_dx_order','codes_icd10_pcs_order','pharma'),
                'format'=>'gzip','filename','add_drop'=> TRUE,'add_insert'=>TRUE,'newline'=> "\n");
    
    $filename = APPPATH.'\\backups\\' .'backup-' . date('d-m-Y') . ' .gz';
    if(!file_exists($filename)){
        get_instance()->load->dbutil();
        file_put_contents( $filename, $this->dbutil->backup($prefs));
    }
    

    at the bottom of my config.php file.

    Move this to a model an allow it to autoload, and you will be fine.

提交回复
热议问题