$folder=FCPATH."application\\models\\new.sql";
$filez=fopen($folder,'w');
$r2=str_replace("cms_project_db","new_cms",$filez);
$new=fwrite($filez,$r2);
$content=file_get_contents($new);
$arr=explode(";",$content);
foreach($arr as $value=>$val)
{
$this->db->query($val);
}
我想从SQL转储文件获取所有内容并更改数据库名称然后执行所有查询,但是我收到此错误:
发生数据库错误
答案 0 :(得分:0)
您可以使用以下脚本,希望它能为您提供帮助:
$this->load->dbutil();
$prefs = array(
'format' => 'zip',
'filename' => 'my_backup.sql'
);
$backup =& $this->dbutil->backup($prefs);
$db_name = 'backup-'. date("Y-m-d-H-i-s") .'.zip';
$save = 'path_to_file/'.$db_name;
$this->load->helper('file');
write_file($save, $backup);
$this->load->helper('download');
force_download($db_name, $backup);