我正在尝试进行MySQL数据库备份并保存.sql
文件。实用程序似乎处理得很好,但在编写文件时。什么都没发生。不确定有什么问题?路径或代码
public function mysql_backup()
{
// Load the DB utility class
$this->load->dbutil();
$date = new DateTime();
$time = $date->format('Y-m-d_H-i-s');
// Backup your entire database and assign it to a variable
$prefs = array(
'tables' => array(), // Array of tables to backup.
'ignore' => array(), // List of tables to omit from the backup
'format' => 'txt', // gzip, zip, txt
'filename' => 'sql_backup_'.$time.'.sql', // File name - NEEDED ONLY WITH ZIP FILES
'add_drop' => TRUE, // Whether to add DROP TABLE statements to backup file
'add_insert' => TRUE, // Whether to add INSERT data to backup file
'newline' => "\n" // Newline character used in backup file
);
$backup = $this->dbutil->backup($prefs);
// Load the file helper and write the file to your server
write_file('./backup/sql_backup_'.$time.'.sql', $backup);
echo '<h2>Cron Successfully Runned.</h2>';
}
答案 0 :(得分:0)
在我看来,你并没有加载file
助手。
尝试在代码
$this->load->helper('file');
public function mysql_backup()
{
// Load the DB utility class
$this->load->helper('file');
$this->load->dbutil();
$date = new DateTime();
$time = $date->format('Y-m-d_H-i-s');
// Backup your entire database and assign it to a variable
$prefs = array(
'tables' => array(), // Array of tables to backup.
'ignore' => array(), // List of tables to omit from the backup
'format' => 'txt', // gzip, zip, txt
'filename' => 'sql_backup_'.$time.'.sql', // File name - NEEDED ONLY WITH ZIP FILES
'add_drop' => TRUE, // Whether to add DROP TABLE statements to backup file
'add_insert' => TRUE, // Whether to add INSERT data to backup file
'newline' => "\n" // Newline character used in backup file
);
$backup = $this->dbutil->backup($prefs);
// Load the file helper and write the file to your server
write_file('./backup/sql_backup_'.$time.'.sql', $backup);
echo '<h2>Cron Successfully Runned.</h2>';
}