我一直在研究 CodeIgniter 附带的用户指南。我对 dbutil() 方法非常感兴趣。特别是以下代码行:

// Load the DB utility class
$this->load->dbutil();

// Backup your entire database and assign it to a variable
$backup =& $this->dbutil->backup();

// Load the file helper and write the file to your server
$this->load->helper('file');
write_file('/path/to/mybackup.gz', $backup);

// Load the download helper and send the file to your desktop
$this->load->helper('download');
force_download('mybackup.gz', $backup);

它应该备份当前加载的 MySQL 数据库。但不幸的是,它不起作用,我收到以下消息:



我在这里缺少什么?任何帮助将非常感激。

最佳答案

试试这个,如果你愿意,你可以将格式 zip 更改为 gz :)

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

关于php - 使用 CodeIgniter 备份 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14093020/

10-17 00:42