如何使用codeigniter获取数据库名称并将数据库导出到具有该数据库名称的文件中?

当我尝试这种方式时,将创建备份文件,但不会将其与数据库名称一起保存。

$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);

最佳答案

试试这个

$NAME=$this->db->database;
$this->load->dbutil();
$prefs = array(
'format' => 'zip',
'filename' => 'my_db_backup.sql'
);
$backup =& $this->dbutil->backup($prefs);
$db_name = $NAME.'.zip';
$save = 'public/uploads/'.$db_name;
$this->load->helper('file');
write_file($save, $backup);
$this->load->helper('download');
force_download($db_name, $backup);

关于mysql - 如何在Codeigniter中导出自己的名称的完整数据库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47569513/

10-15 18:38